Skip to content

Commit 87c7bf2

Browse files
committed
changes after review
1 parent fa8bdf4 commit 87c7bf2

File tree

5 files changed

+3406
-496
lines changed

5 files changed

+3406
-496
lines changed

internal/namespaces/container/v1beta1/custom_container_test.go

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,15 @@ func Test_CreateContainer(t *testing.T) {
5050
}))
5151
}
5252

53-
func createContainer(metaKey string) core.BeforeFunc {
54-
return core.ExecStoreBeforeCmd(metaKey, fmt.Sprintf(
55-
"scw container container create namespace-id={{ .Namespace.ID }} name=%s deploy=true -w",
56-
core.GetRandomName("test")))
57-
}
58-
59-
func createContainerWithImage(metaKey string, registryImageMetaKey string) core.BeforeFunc {
60-
return core.ExecStoreBeforeCmd(metaKey, fmt.Sprintf(
61-
"scw container container create namespace-id={{ .ContainerNamespace.ID }} name=%s registry-image={{ (index .%s 0).FullName }}:latest port=80 deploy=true -w",
62-
core.GetRandomName("test"),
63-
registryImageMetaKey,
64-
))
65-
}
66-
67-
func deleteRegistryNamespace(metaKey string) core.AfterFunc {
68-
return func(ctx *core.AfterFuncCtx) error {
69-
return core.ExecAfterCmd("scw registry namespace delete {{ ." + metaKey + ".ID }}")(ctx)
70-
}
71-
}
72-
7353
func Test_UpdateContainer(t *testing.T) {
7454
t.Run("Simple", core.Test(&core.TestConfig{
7555
Commands: container.GetCommands(),
7656
BeforeFunc: core.BeforeFuncCombine(
7757
createNamespace("Namespace"),
78-
createContainer("Container"),
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+
)),
7962
),
8063
Cmd: "scw container container update {{ .Container.ID }} tags.0=new_tag port=80 cpu-limit=1500",
8164
Check: core.TestCheckCombine(
@@ -94,69 +77,82 @@ func Test_UpdateContainer(t *testing.T) {
9477
),
9578
}))
9679

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+
9788
t.Run("RegistryImage", core.Test(&core.TestConfig{
9889
Commands: core.NewCommandsMerge(
9990
container.GetCommands(),
10091
registry.GetCommands(),
10192
),
10293
BeforeFunc: core.BeforeFuncCombine(
10394
core.ExecStoreBeforeCmd(
104-
"RegistryNamespace",
95+
registryNamespaceMetaKey,
10596
fmt.Sprintf("scw registry namespace create name=%s is-public=false",
10697
core.GetRandomName("test-ctn-update-rg-img"),
10798
),
10899
),
109100
core.BeforeFuncWhenUpdatingCassette(
110101
core.BeforeFuncCombine(
111102
core.ExecBeforeCmd("scw registry login"),
112-
testhelpers.PushRegistryImage(
113-
"nginx:1.28.0-alpine",
114-
"RegistryNamespace",
115-
"nginx-1-28-0-alpine",
116-
),
117-
testhelpers.PushRegistryImage(
118-
"nginx:1.29.2-alpine",
119-
"RegistryNamespace",
120-
"nginx-1-29-2-alpine",
121-
),
103+
testhelpers.PushRegistryImage(lighttpdImage, registryNamespaceMetaKey),
104+
testhelpers.PushRegistryImage(nginxImage, registryNamespaceMetaKey),
122105
),
123106
),
124-
core.BeforeFuncCombine(
125-
testhelpers.StoreImageInMeta(
126-
"RegistryImageNginx28",
127-
"RegistryNamespace",
128-
"nginx-1-28-0-alpine",
129-
),
130-
testhelpers.StoreImageInMeta(
131-
"RegistryImageNginx29",
132-
"RegistryNamespace",
133-
"nginx-1-29-2-alpine",
134-
),
107+
testhelpers.StoreImageIdentifierInMeta(
108+
registryNamespaceMetaKey,
109+
lighttpdImage,
110+
lighttpdImageMetaKey,
111+
),
112+
testhelpers.StoreImageIdentifierInMeta(
113+
registryNamespaceMetaKey,
114+
nginxImage,
115+
nginxImageMetaKey,
135116
),
136-
createNamespace("ContainerNamespace"),
137-
createContainerWithImage("Container", "RegistryImageNginx28"),
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,
138130
),
139-
Cmd: "scw container container update {{ .Container.ID }} registry-image={{ (index .RegistryImageNginx29 0).FullName }}:latest port=80 redeploy=true -w",
140131
Check: core.TestCheckCombine(
141132
func(t *testing.T, ctx *core.CheckFuncCtx) {
142133
t.Helper()
143134
c := ctx.Result.(*containerSDK.Container)
144-
145135
// Check image
146-
expectedImageName := ctx.Meta.Render(
147-
"{{ (index .RegistryImageNginx29 0).FullName }}:latest",
148-
)
136+
expectedImageName := ctx.Meta.Render(fmt.Sprintf("{{ .%s }}", nginxImageMetaKey))
149137
assert.Equal(t, expectedImageName, c.RegistryImage)
150-
151138
// Check status
152139
assert.Equal(t, containerSDK.ContainerStatusReady, c.Status)
153140
},
154141
core.TestCheckExitCode(0),
155142
core.TestCheckGolden(),
156143
),
157144
AfterFunc: core.AfterFuncCombine(
158-
deleteNamespace("ContainerNamespace"),
159-
deleteRegistryNamespace("RegistryNamespace"),
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+
},
160156
),
161157
}))
162158
}

0 commit comments

Comments
 (0)