|
| 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 | +) |
| 11 | + |
| 12 | +func Test_RegistryTagDelete(t *testing.T) { |
| 13 | + registryNamespaceMetaKey := "RegistryNamespace" |
| 14 | + helloWorldImage := "hello-world:latest" |
| 15 | + helloWorldImageMetaKey := "HelloWorldImage" |
| 16 | + tagIDMetaKey := "TagID" |
| 17 | + |
| 18 | + t.Run("simple", core.Test(&core.TestConfig{ |
| 19 | + Commands: registry.GetCommands(), |
| 20 | + BeforeFunc: core.BeforeFuncCombine( |
| 21 | + core.ExecStoreBeforeCmd( |
| 22 | + registryNamespaceMetaKey, |
| 23 | + fmt.Sprintf("scw registry namespace create name=%s is-public=false", |
| 24 | + core.GetRandomName("test-rg-tag-delete"), |
| 25 | + ), |
| 26 | + ), |
| 27 | + core.BeforeFuncWhenUpdatingCassette( |
| 28 | + core.BeforeFuncCombine( |
| 29 | + core.ExecBeforeCmd("scw registry login"), |
| 30 | + testhelpers.PushRegistryImage(helloWorldImage, registryNamespaceMetaKey), |
| 31 | + ), |
| 32 | + ), |
| 33 | + testhelpers.StoreImageIdentifierInMeta( |
| 34 | + registryNamespaceMetaKey, |
| 35 | + helloWorldImage, |
| 36 | + helloWorldImageMetaKey, |
| 37 | + ), |
| 38 | + testhelpers.StoreTagIDInMeta(registryNamespaceMetaKey, helloWorldImage, tagIDMetaKey), |
| 39 | + ), |
| 40 | + Cmd: fmt.Sprintf("scw registry tag delete {{ .%s }}", tagIDMetaKey), |
| 41 | + Check: core.TestCheckCombine( |
| 42 | + core.TestCheckGolden(), |
| 43 | + core.TestCheckExitCode(0), |
| 44 | + ), |
| 45 | + AfterFunc: func(ctx *core.AfterFuncCtx) error { |
| 46 | + return core.ExecAfterCmd( |
| 47 | + fmt.Sprintf( |
| 48 | + "scw registry namespace delete {{ .%s.ID }}", |
| 49 | + registryNamespaceMetaKey, |
| 50 | + ), |
| 51 | + )( |
| 52 | + ctx, |
| 53 | + ) |
| 54 | + }, |
| 55 | + })) |
| 56 | + |
| 57 | + t.Run("timeout-ok", core.Test(&core.TestConfig{ |
| 58 | + Commands: registry.GetCommands(), |
| 59 | + BeforeFunc: core.BeforeFuncCombine( |
| 60 | + core.ExecStoreBeforeCmd( |
| 61 | + registryNamespaceMetaKey, |
| 62 | + fmt.Sprintf("scw registry namespace create name=%s is-public=false", |
| 63 | + core.GetRandomName("test-rg-tag-delete"), |
| 64 | + ), |
| 65 | + ), |
| 66 | + core.BeforeFuncWhenUpdatingCassette( |
| 67 | + core.BeforeFuncCombine( |
| 68 | + core.ExecBeforeCmd("scw registry login"), |
| 69 | + testhelpers.PushRegistryImage(helloWorldImage, registryNamespaceMetaKey), |
| 70 | + ), |
| 71 | + ), |
| 72 | + testhelpers.StoreImageIdentifierInMeta( |
| 73 | + registryNamespaceMetaKey, |
| 74 | + helloWorldImage, |
| 75 | + helloWorldImageMetaKey, |
| 76 | + ), |
| 77 | + testhelpers.StoreTagIDInMeta(registryNamespaceMetaKey, helloWorldImage, tagIDMetaKey), |
| 78 | + ), |
| 79 | + Cmd: fmt.Sprintf("scw registry tag delete {{ .%s }} timeout=1s", tagIDMetaKey), |
| 80 | + Check: core.TestCheckCombine( |
| 81 | + core.TestCheckGolden(), |
| 82 | + core.TestCheckExitCode(0), |
| 83 | + ), |
| 84 | + AfterFunc: func(ctx *core.AfterFuncCtx) error { |
| 85 | + return core.ExecAfterCmd( |
| 86 | + fmt.Sprintf( |
| 87 | + "scw registry namespace delete {{ .%s.ID }}", |
| 88 | + registryNamespaceMetaKey, |
| 89 | + ), |
| 90 | + )( |
| 91 | + ctx, |
| 92 | + ) |
| 93 | + }, |
| 94 | + })) |
| 95 | +} |
0 commit comments