66
77 "github.com/scaleway/scaleway-cli/v2/core"
88 container "github.com/scaleway/scaleway-cli/v2/internal/namespaces/container/v1beta1"
9+ "github.com/scaleway/scaleway-cli/v2/internal/namespaces/registry/v1"
10+ "github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
911 containerSDK "github.com/scaleway/scaleway-sdk-go/api/container/v1beta1"
1012 "github.com/stretchr/testify/assert"
1113)
@@ -20,7 +22,7 @@ func deleteNamespace(metaKey string) core.AfterFunc {
2022 }
2123}
2224
23- func Test_Create (t * testing.T ) {
25+ func Test_CreateContainer (t * testing.T ) {
2426 commands := container .GetCommands ()
2527
2628 t .Run ("Simple" , core .Test (& core.TestConfig {
@@ -47,3 +49,110 @@ func Test_Create(t *testing.T) {
4749 DisableParallel : true ,
4850 }))
4951}
52+
53+ func Test_UpdateContainer (t * testing.T ) {
54+ t .Run ("Simple" , core .Test (& core.TestConfig {
55+ Commands : container .GetCommands (),
56+ BeforeFunc : core .BeforeFuncCombine (
57+ createNamespace ("Namespace" ),
58+ core .ExecStoreBeforeCmd ("Container" , fmt .Sprintf (
59+ "scw container container create namespace-id={{ .Namespace.ID }} name=%s deploy=true -w" ,
60+ core .GetRandomName ("test" ),
61+ )),
62+ ),
63+ Cmd : "scw container container update {{ .Container.ID }} tags.0=new_tag port=80 cpu-limit=1500" ,
64+ Check : core .TestCheckCombine (
65+ func (t * testing.T , ctx * core.CheckFuncCtx ) {
66+ t .Helper ()
67+ c := ctx .Result .(* containerSDK.Container )
68+ assert .Equal (t , []string {"new_tag" }, c .Tags )
69+ assert .Equal (t , uint32 (80 ), c .Port , "unexpected port number" )
70+ assert .Equal (t , uint32 (1500 ), c .CPULimit , "unexpected CPU limit" )
71+ },
72+ core .TestCheckExitCode (0 ),
73+ core .TestCheckGolden (),
74+ ),
75+ AfterFunc : core .AfterFuncCombine (
76+ deleteNamespace ("Namespace" ),
77+ ),
78+ }))
79+
80+ lighttpdImage := "sebp/lighttpd:latest"
81+ nginxImage := "nginx:1.29.2-alpine"
82+ lighttpdImageMetaKey := "LighttpdImage"
83+ nginxImageMetaKey := "NginxImage"
84+ registryNamespaceMetaKey := "RegistryNamespace"
85+ containerNamespaceMetaKey := "ContainerNamespace"
86+ containerMetaKey := "Container"
87+
88+ t .Run ("RegistryImage" , core .Test (& core.TestConfig {
89+ Commands : core .NewCommandsMerge (
90+ container .GetCommands (),
91+ registry .GetCommands (),
92+ ),
93+ BeforeFunc : core .BeforeFuncCombine (
94+ core .ExecStoreBeforeCmd (
95+ registryNamespaceMetaKey ,
96+ fmt .Sprintf ("scw registry namespace create name=%s is-public=false" ,
97+ core .GetRandomName ("test-ctn-update-rg-img" ),
98+ ),
99+ ),
100+ core .BeforeFuncWhenUpdatingCassette (
101+ core .BeforeFuncCombine (
102+ core .ExecBeforeCmd ("scw registry login" ),
103+ testhelpers .PushRegistryImage (lighttpdImage , registryNamespaceMetaKey ),
104+ testhelpers .PushRegistryImage (nginxImage , registryNamespaceMetaKey ),
105+ ),
106+ ),
107+ testhelpers .StoreImageIdentifierInMeta (
108+ registryNamespaceMetaKey ,
109+ lighttpdImage ,
110+ lighttpdImageMetaKey ,
111+ ),
112+ testhelpers .StoreImageIdentifierInMeta (
113+ registryNamespaceMetaKey ,
114+ nginxImage ,
115+ nginxImageMetaKey ,
116+ ),
117+ createNamespace (containerNamespaceMetaKey ),
118+ core .ExecStoreBeforeCmd (containerMetaKey , fmt .Sprintf (
119+ "scw container container create namespace-id={{ .%s.ID }} name=%s registry-image={{ .%s }} port=80 deploy=true -w" ,
120+ containerNamespaceMetaKey ,
121+ core .GetRandomName ("test" ),
122+ lighttpdImageMetaKey ,
123+ )),
124+ // NB: after this step, the container with the sebp/lighttpd image will deploy but stay in error state because it has no content to serve
125+ ),
126+ Cmd : fmt .Sprintf (
127+ "scw container container update {{ .%s.ID }} registry-image={{ .%s }} port=80 redeploy=true -w" ,
128+ containerMetaKey ,
129+ nginxImageMetaKey ,
130+ ),
131+ Check : core .TestCheckCombine (
132+ func (t * testing.T , ctx * core.CheckFuncCtx ) {
133+ t .Helper ()
134+ c := ctx .Result .(* containerSDK.Container )
135+ // Check image
136+ expectedImageName := ctx .Meta .Render (fmt .Sprintf ("{{ .%s }}" , nginxImageMetaKey ))
137+ assert .Equal (t , expectedImageName , c .RegistryImage )
138+ // Check status
139+ assert .Equal (t , containerSDK .ContainerStatusReady , c .Status )
140+ },
141+ core .TestCheckExitCode (0 ),
142+ core .TestCheckGolden (),
143+ ),
144+ AfterFunc : core .AfterFuncCombine (
145+ deleteNamespace (containerNamespaceMetaKey ),
146+ func (ctx * core.AfterFuncCtx ) error {
147+ return core .ExecAfterCmd (
148+ fmt .Sprintf (
149+ "scw registry namespace delete {{ .%s.ID }}" ,
150+ registryNamespaceMetaKey ,
151+ ),
152+ )(
153+ ctx ,
154+ )
155+ },
156+ ),
157+ }))
158+ }
0 commit comments