Skip to content

Commit 6f95c18

Browse files
authored
test(registry): fix test for image list (#1059)
1 parent 0cada49 commit 6f95c18

File tree

4 files changed

+806
-25
lines changed

4 files changed

+806
-25
lines changed

internal/core/testing.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,9 @@ func ExecStoreBeforeCmd(metaKey, cmd string) BeforeFunc {
453453
}
454454
}
455455

456-
func BeforeFuncOsExec(cmdStrings ...[]string) BeforeFunc {
456+
func BeforeFuncOsExec(cmd string, args ...string) BeforeFunc {
457457
return func(ctx *BeforeFuncCtx) error {
458-
for _, cmdString := range cmdStrings {
459-
err := exec.Command(cmdString[0], cmdString[1:len(cmdString)-1]...).Run()
460-
if err != nil {
461-
return err
462-
}
463-
}
464-
return nil
458+
return exec.Command(cmd, args...).Run()
465459
}
466460
}
467461

internal/namespaces/registry/v1/custom_image_test.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ package registry
33
import (
44
"fmt"
55
"testing"
6-
"time"
76

87
"github.com/scaleway/scaleway-cli/internal/core"
98
"github.com/scaleway/scaleway-sdk-go/api/registry/v1"
109
)
1110

1211
func Test_ImageList(t *testing.T) {
13-
t.Skipf("Waiting for registry API to fix cache problems")
1412
t.Run("Simple", core.Test(&core.TestConfig{
1513
Commands: GetCommands(),
1614
BeforeFunc: core.BeforeFuncCombine(
17-
core.ExecBeforeCmd("scw registry namespace create name=cli-public-namespace is-public=true"),
18-
core.ExecBeforeCmd("scw registry namespace create name=cli-private-namespace is-public=false"),
15+
core.ExecStoreBeforeCmd("PublicNamespace", "scw registry namespace create name=cli-public-namespace is-public=true"),
16+
core.ExecStoreBeforeCmd("PrivateNamespace", "scw registry namespace create name=cli-private-namespace is-public=false"),
1917
core.BeforeFuncWhenUpdatingCassette(
2018
core.ExecBeforeCmd("scw registry login"),
2119
),
@@ -73,25 +71,19 @@ func Test_ImageList(t *testing.T) {
7371
core.TestCheckExitCode(0),
7472
),
7573
AfterFunc: core.AfterFuncCombine(
76-
core.ExecAfterCmd("scw registry namespace remove cli-public-namespace"),
77-
core.ExecAfterCmd("scw registry namespace remove cli-private-namespace"),
74+
core.ExecAfterCmd("scw registry namespace delete {{ .PublicNamespace.ID }}"),
75+
core.ExecAfterCmd("scw registry namespace delete {{ .PrivateNamespace.ID }}"),
7876
),
7977
}))
8078
}
8179

8280
func setupImage(dockerImage string, namespaceEndpoint string, imageName string, visibility registry.ImageVisibility) core.BeforeFunc {
8381
remote := fmt.Sprintf("%s/%s:latest", namespaceEndpoint, imageName)
8482
return core.BeforeFuncCombine(
85-
core.BeforeFuncOsExec(
86-
[]string{"docker", fmt.Sprintf("pull %s", dockerImage)},
87-
[]string{"docker", fmt.Sprintf("tag %s %s", dockerImage, remote)},
88-
[]string{"docker", fmt.Sprintf("push %s", remote)},
89-
),
90-
func(ctx *core.BeforeFuncCtx) error {
91-
time.Sleep(2 * time.Minute)
92-
return nil
93-
},
94-
core.ExecStoreBeforeCmd("Image", fmt.Sprintf("scw registry image list name=%s", imageName)),
95-
core.ExecBeforeCmd(fmt.Sprintf("scw registry image update {{ index .Image 0 `ID` }} visibility=%s", visibility.String())),
83+
core.BeforeFuncOsExec("docker", "pull", dockerImage),
84+
core.BeforeFuncOsExec("docker", "tag", dockerImage, remote),
85+
core.BeforeFuncOsExec("docker", "push", remote),
86+
core.ExecStoreBeforeCmd("ImageListResult", fmt.Sprintf("scw registry image list name=%s", imageName)),
87+
core.ExecBeforeCmd(fmt.Sprintf(`scw registry image update {{ (index .ImageListResult 0).ID }} visibility=%s`, visibility.String())),
9688
)
9789
}

0 commit comments

Comments
 (0)