|
| 1 | +package registry_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/scaleway/scaleway-cli/v2/core" |
| 8 | + "github.com/scaleway/scaleway-cli/v2/internal/namespaces/registry/v1" |
| 9 | + "github.com/scaleway/scaleway-cli/v2/internal/testhelpers" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | +) |
| 12 | + |
| 13 | +func Test_RegistryTagDelete(t *testing.T) { |
| 14 | + registryNamespaceMetaKey := "RegistryNamespace" |
| 15 | + helloWorldImage := "hello-world:latest" |
| 16 | + helloWorldImageMetaKey := "HelloWorldImage" |
| 17 | + tagIDMetaKey := "TagID" |
| 18 | + |
| 19 | + t.Run("timeout-ok", core.Test(&core.TestConfig{ |
| 20 | + Commands: registry.GetCommands(), |
| 21 | + BeforeFunc: core.BeforeFuncCombine( |
| 22 | + core.ExecStoreBeforeCmd( |
| 23 | + registryNamespaceMetaKey, |
| 24 | + fmt.Sprintf("scw registry namespace create name=%s is-public=false", |
| 25 | + core.GetRandomName("test-rg-tag-delete"), |
| 26 | + ), |
| 27 | + ), |
| 28 | + core.BeforeFuncWhenUpdatingCassette( |
| 29 | + core.BeforeFuncCombine( |
| 30 | + core.ExecBeforeCmd("scw registry login"), |
| 31 | + testhelpers.PushRegistryImage(helloWorldImage, registryNamespaceMetaKey), |
| 32 | + ), |
| 33 | + ), |
| 34 | + testhelpers.StoreImageIdentifierInMeta( |
| 35 | + registryNamespaceMetaKey, |
| 36 | + helloWorldImage, |
| 37 | + helloWorldImageMetaKey, |
| 38 | + ), |
| 39 | + testhelpers.StoreTagIDInMeta(registryNamespaceMetaKey, helloWorldImage, tagIDMetaKey), |
| 40 | + ), |
| 41 | + Cmd: fmt.Sprintf("scw registry tag delete {{ .%s }} timeout=1s", tagIDMetaKey), |
| 42 | + Check: core.TestCheckCombine( |
| 43 | + core.TestCheckGolden(), |
| 44 | + core.TestCheckExitCode(0), |
| 45 | + ), |
| 46 | + AfterFunc: func(ctx *core.AfterFuncCtx) error { |
| 47 | + return core.ExecAfterCmd( |
| 48 | + fmt.Sprintf( |
| 49 | + "scw registry namespace delete {{ .%s.ID }}", |
| 50 | + registryNamespaceMetaKey, |
| 51 | + ), |
| 52 | + )( |
| 53 | + ctx, |
| 54 | + ) |
| 55 | + }, |
| 56 | + })) |
| 57 | + |
| 58 | + t.Run("timeout-too-short", core.Test(&core.TestConfig{ |
| 59 | + Commands: registry.GetCommands(), |
| 60 | + BeforeFunc: core.BeforeFuncCombine( |
| 61 | + core.ExecStoreBeforeCmd( |
| 62 | + registryNamespaceMetaKey, |
| 63 | + fmt.Sprintf("scw registry namespace create name=%s is-public=false", |
| 64 | + core.GetRandomName("test-rg-tag-delete"), |
| 65 | + ), |
| 66 | + ), |
| 67 | + core.BeforeFuncWhenUpdatingCassette( |
| 68 | + core.BeforeFuncCombine( |
| 69 | + core.ExecBeforeCmd("scw registry login"), |
| 70 | + testhelpers.PushRegistryImage(helloWorldImage, registryNamespaceMetaKey), |
| 71 | + ), |
| 72 | + ), |
| 73 | + testhelpers.StoreImageIdentifierInMeta( |
| 74 | + registryNamespaceMetaKey, |
| 75 | + helloWorldImage, |
| 76 | + helloWorldImageMetaKey, |
| 77 | + ), |
| 78 | + testhelpers.StoreTagIDInMeta(registryNamespaceMetaKey, helloWorldImage, tagIDMetaKey), |
| 79 | + ), |
| 80 | + Cmd: fmt.Sprintf("scw registry tag delete {{ .%s }} timeout=1µs", tagIDMetaKey), |
| 81 | + Check: core.TestCheckCombine( |
| 82 | + core.TestCheckGolden(), |
| 83 | + core.TestCheckExitCode(1), |
| 84 | + func(t *testing.T, ctx *core.CheckFuncCtx) { |
| 85 | + t.Helper() |
| 86 | + assert.Contains(t, string(ctx.Stderr), "context deadline exceeded") |
| 87 | + }, |
| 88 | + ), |
| 89 | + AfterFunc: func(ctx *core.AfterFuncCtx) error { |
| 90 | + return core.ExecAfterCmd( |
| 91 | + fmt.Sprintf( |
| 92 | + "scw registry namespace delete {{ .%s.ID }}", |
| 93 | + registryNamespaceMetaKey, |
| 94 | + ), |
| 95 | + )( |
| 96 | + ctx, |
| 97 | + ) |
| 98 | + }, |
| 99 | + })) |
| 100 | +} |
0 commit comments