|
| 1 | +package instance |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/alecthomas/assert" |
| 7 | + "github.com/scaleway/scaleway-cli/v2/internal/core" |
| 8 | + "github.com/scaleway/scaleway-sdk-go/api/instance/v1" |
| 9 | +) |
| 10 | + |
| 11 | +func Test_UpdateSnapshot(t *testing.T) { |
| 12 | + t.Run("Simple", func(t *testing.T) { |
| 13 | + t.Run("Change tags", core.Test(&core.TestConfig{ |
| 14 | + Commands: GetCommands(), |
| 15 | + BeforeFunc: core.BeforeFuncCombine( |
| 16 | + createVolume("Volume", 10, instance.VolumeVolumeTypeBSSD), |
| 17 | + core.ExecStoreBeforeCmd("CreateSnapshot", "scw instance snapshot create volume-id={{ .Volume.ID }} name=cli-test-snapshot-update-tags tags.0=foo tags.1=bar"), |
| 18 | + ), |
| 19 | + Cmd: "scw instance snapshot update -w {{ .CreateSnapshot.Snapshot.ID }} tags.0=bar tags.1=foo", |
| 20 | + Check: core.TestCheckCombine( |
| 21 | + core.TestCheckGolden(), |
| 22 | + core.TestCheckExitCode(0), |
| 23 | + func(t *testing.T, ctx *core.CheckFuncCtx) { |
| 24 | + snapshot := ctx.Result.(*instance.Snapshot) |
| 25 | + assert.Equal(t, snapshot.Name, "cli-test-snapshot-update-tags") |
| 26 | + assert.Len(t, snapshot.Tags, 2) |
| 27 | + assert.Equal(t, snapshot.Tags[0], "bar") |
| 28 | + assert.Equal(t, snapshot.Tags[1], "foo") |
| 29 | + }, |
| 30 | + ), |
| 31 | + AfterFunc: core.AfterFuncCombine( |
| 32 | + deleteSnapshot("CreateSnapshot"), |
| 33 | + deleteVolume("Volume"), |
| 34 | + ), |
| 35 | + })) |
| 36 | + t.Run("Change name", core.Test(&core.TestConfig{ |
| 37 | + Commands: GetCommands(), |
| 38 | + BeforeFunc: core.BeforeFuncCombine( |
| 39 | + createVolume("Volume", 10, instance.VolumeVolumeTypeBSSD), |
| 40 | + core.ExecStoreBeforeCmd("CreateSnapshot", "scw instance snapshot create volume-id={{ .Volume.ID }} name=cli-test-snapshot-update-name tags.0=foo tags.1=bar"), |
| 41 | + ), |
| 42 | + Cmd: "scw instance snapshot update -w {{ .CreateSnapshot.Snapshot.ID }} name=cli-test-snapshot-update-name-updated", |
| 43 | + Check: core.TestCheckCombine( |
| 44 | + core.TestCheckGolden(), |
| 45 | + core.TestCheckExitCode(0), |
| 46 | + func(t *testing.T, ctx *core.CheckFuncCtx) { |
| 47 | + snapshot := ctx.Result.(*instance.Snapshot) |
| 48 | + assert.Equal(t, snapshot.Name, "cli-test-snapshot-update-name-updated") |
| 49 | + assert.Len(t, snapshot.Tags, 2) |
| 50 | + assert.Equal(t, snapshot.Tags[0], "foo") |
| 51 | + assert.Equal(t, snapshot.Tags[1], "bar") |
| 52 | + }, |
| 53 | + ), |
| 54 | + AfterFunc: core.AfterFuncCombine( |
| 55 | + deleteSnapshot("CreateSnapshot"), |
| 56 | + deleteVolume("Volume"), |
| 57 | + ), |
| 58 | + })) |
| 59 | + }) |
| 60 | +} |
0 commit comments