2020-09-14 21:56:35 -04:00
|
|
|
package manifest
|
|
|
|
|
|
|
|
import (
|
2022-02-25 07:11:27 -05:00
|
|
|
"io"
|
2020-09-14 21:56:35 -04:00
|
|
|
"testing"
|
|
|
|
|
2022-02-25 07:11:27 -05:00
|
|
|
"github.com/docker/cli/cli/manifest/store"
|
2020-09-14 21:56:35 -04:00
|
|
|
"github.com/docker/cli/internal/test"
|
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// create two manifest lists and remove them both
|
|
|
|
func TestRmSeveralManifests(t *testing.T) {
|
2023-11-20 11:38:50 -05:00
|
|
|
manifestStore := store.NewStore(t.TempDir())
|
2020-09-14 21:56:35 -04:00
|
|
|
|
|
|
|
cli := test.NewFakeCli(nil)
|
2023-11-20 11:38:50 -05:00
|
|
|
cli.SetManifestStore(manifestStore)
|
2020-09-14 21:56:35 -04:00
|
|
|
|
|
|
|
list1 := ref(t, "first:1")
|
|
|
|
namedRef := ref(t, "alpine:3.0")
|
2023-11-20 11:38:50 -05:00
|
|
|
err := manifestStore.Save(list1, namedRef, fullImageManifest(t, namedRef))
|
2020-09-14 21:56:35 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
namedRef = ref(t, "alpine:3.1")
|
2023-11-20 11:38:50 -05:00
|
|
|
err = manifestStore.Save(list1, namedRef, fullImageManifest(t, namedRef))
|
2020-09-14 21:56:35 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
list2 := ref(t, "second:2")
|
|
|
|
namedRef = ref(t, "alpine:3.2")
|
2023-11-20 11:38:50 -05:00
|
|
|
err = manifestStore.Save(list2, namedRef, fullImageManifest(t, namedRef))
|
2020-09-14 21:56:35 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
cmd := newRmManifestListCommand(cli)
|
|
|
|
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
|
2022-02-25 07:11:27 -05:00
|
|
|
cmd.SetOut(io.Discard)
|
2020-09-14 21:56:35 -04:00
|
|
|
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) {
|
2023-11-20 11:38:50 -05:00
|
|
|
manifestStore := store.NewStore(t.TempDir())
|
2020-09-14 21:56:35 -04:00
|
|
|
|
|
|
|
cli := test.NewFakeCli(nil)
|
2023-11-20 11:38:50 -05:00
|
|
|
cli.SetManifestStore(manifestStore)
|
2020-09-14 21:56:35 -04:00
|
|
|
|
|
|
|
list2 := ref(t, "second:2")
|
|
|
|
namedRef := ref(t, "alpine:3.2")
|
2023-11-20 11:38:50 -05:00
|
|
|
err := manifestStore.Save(list2, namedRef, fullImageManifest(t, namedRef))
|
2020-09-14 21:56:35 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
cmd := newRmManifestListCommand(cli)
|
|
|
|
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
|
2022-02-25 07:11:27 -05:00
|
|
|
cmd.SetOut(io.Discard)
|
2020-09-14 21:56:35 -04:00
|
|
|
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")
|
|
|
|
}
|