DockerCLI/cli/command/manifest/rm_test.go

66 lines
1.9 KiB
Go
Raw Normal View History

Subcommand `docker manifest rm` Squashed commit of the following: commit b9ef85e74833ba405f68cfc20989c69d64bac4e9 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Mon Sep 14 21:39:57 2020 -0400 Fix bash completion https://github.com/docker/cli/pull/2449#pullrequestreview-488110510 Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> commit 8c46bd6e6ed151bb43865c8b1d79c00fd62e4345 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Sun Sep 13 01:48:12 2020 -0400 Add tests for docker manifest rm Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> commit 7e3d9a9bc60e44d96953093fa0b1bc3397ca7813 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Sun Sep 13 00:55:37 2020 -0400 docker manifest rm multiple args Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> commit 30466e28d28f6722053c5a232e99ddbae8222715 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Sun Sep 13 00:01:20 2020 -0400 No need to search before Remove https://github.com/docker/cli/pull/2449#discussion_r485544044 Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> commit ccdc4ed0a620cf8c9ec6ecc6804d1a45f7c61be5 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Sat Sep 12 23:42:41 2020 -0400 Completion should also handle --help https://github.com/docker/cli/pull/2449#discussion_r443140909 Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> commit ed260afa71a4f8feb6550f79692e47ad7430d786 Merge: 46c61d85e9 2955ece024 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Sat Sep 12 23:31:54 2020 -0400 Merge branch 'master' into manifest-rm commit 46c61d85e973cc9fdd28d42db9ecebe373e9b942 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Fri Apr 17 21:53:33 2020 -0400 Remove extra space Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> commit 6d31d26c10e8d395ab08561cdb9b29829bb4bd91 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Fri Apr 17 21:15:21 2020 -0400 Bash completion for `docker manifest rm` Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> commit 3c8c843deb2f751a5f51ee6fcaa75da2a4525d99 Author: Jennings Zhang <jenni_zh@protonmail.com> Date: Fri Apr 17 21:05:50 2020 -0400 Frankenstein a `docker manifest rm` command Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com> Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
2020-09-14 21:56:35 -04:00
package manifest
import (
"io/ioutil"
"testing"
"github.com/docker/cli/internal/test"
"gotest.tools/v3/assert"
)
// create two manifest lists and remove them both
func TestRmSeveralManifests(t *testing.T) {
store, cleanup := newTempManifestStore(t)
defer cleanup()
cli := test.NewFakeCli(nil)
cli.SetManifestStore(store)
list1 := ref(t, "first:1")
namedRef := ref(t, "alpine:3.0")
err := store.Save(list1, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)
namedRef = ref(t, "alpine:3.1")
err = store.Save(list1, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)
list2 := ref(t, "second:2")
namedRef = ref(t, "alpine:3.2")
err = store.Save(list2, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)
cmd := newRmManifestListCommand(cli)
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
cmd.SetOut(ioutil.Discard)
err = cmd.Execute()
assert.NilError(t, err)
_, search1 := cli.ManifestStore().GetList(list1)
_, search2 := cli.ManifestStore().GetList(list2)
assert.Error(t, search1, "No such manifest: example.com/first:1")
assert.Error(t, search2, "No such manifest: example.com/second:2")
}
// attempt to remove a manifest list which was never created
func TestRmManifestNotCreated(t *testing.T) {
store, cleanup := newTempManifestStore(t)
defer cleanup()
cli := test.NewFakeCli(nil)
cli.SetManifestStore(store)
list2 := ref(t, "second:2")
namedRef := ref(t, "alpine:3.2")
err := store.Save(list2, namedRef, fullImageManifest(t, namedRef))
assert.NilError(t, err)
cmd := newRmManifestListCommand(cli)
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
cmd.SetOut(ioutil.Discard)
err = cmd.Execute()
assert.Error(t, err, "No such manifest: example.com/first:1")
_, err = cli.ManifestStore().GetList(list2)
assert.Error(t, err, "No such manifest: example.com/second:2")
}