mirror of https://github.com/docker/cli.git
cli/command/manifest: remove deprecated io/ioutil and use t.TempDir()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d14b5bff80
commit
43795ec8f7
|
@ -1,9 +1,10 @@
|
|||
package manifest
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/cli/manifest/store"
|
||||
"github.com/docker/cli/internal/test"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
|
@ -33,14 +34,13 @@ func TestManifestAnnotateError(t *testing.T) {
|
|||
cli := test.NewFakeCli(nil)
|
||||
cmd := newAnnotateCommand(cli)
|
||||
cmd.SetArgs(tc.args)
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestAnnotate(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -51,7 +51,7 @@ func TestManifestAnnotate(t *testing.T) {
|
|||
|
||||
cmd := newAnnotateCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/fake:0.0"})
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
expectedError := "manifest for image example.com/fake:0.0 does not exist"
|
||||
assert.ErrorContains(t, cmd.Execute(), expectedError)
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@ package manifest
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/cli/manifest/store"
|
||||
manifesttypes "github.com/docker/cli/cli/manifest/types"
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/distribution/reference"
|
||||
|
@ -33,15 +34,14 @@ func TestManifestCreateErrors(t *testing.T) {
|
|||
cli := test.NewFakeCli(nil)
|
||||
cmd := newCreateListCommand(cli)
|
||||
cmd.SetArgs(tc.args)
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
}
|
||||
}
|
||||
|
||||
// create a manifest list, then overwrite it, and inspect to see if the old one is still there
|
||||
func TestManifestCreateAmend(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -58,7 +58,7 @@ func TestManifestCreateAmend(t *testing.T) {
|
|||
cmd := newCreateListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.1"})
|
||||
cmd.Flags().Set("amend", "true")
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
err = cmd.Execute()
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
@ -75,8 +75,7 @@ func TestManifestCreateAmend(t *testing.T) {
|
|||
|
||||
// attempt to overwrite a saved manifest and get refused
|
||||
func TestManifestCreateRefuseAmend(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -87,15 +86,14 @@ func TestManifestCreateRefuseAmend(t *testing.T) {
|
|||
|
||||
cmd := newCreateListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
err = cmd.Execute()
|
||||
assert.Error(t, err, "refusing to amend an existing manifest list with no --amend flag")
|
||||
}
|
||||
|
||||
// attempt to make a manifest list without valid images
|
||||
func TestManifestCreateNoManifest(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -110,7 +108,7 @@ func TestManifestCreateNoManifest(t *testing.T) {
|
|||
|
||||
cmd := newCreateListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
err := cmd.Execute()
|
||||
assert.Error(t, err, "No such image: example.com/alpine:3.0")
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ package manifest
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/cli/manifest/store"
|
||||
|
@ -21,13 +20,6 @@ import (
|
|||
"gotest.tools/v3/golden"
|
||||
)
|
||||
|
||||
func newTempManifestStore(t *testing.T) (store.Store, func()) {
|
||||
tmpdir, err := ioutil.TempDir("", "test-manifest-storage")
|
||||
assert.NilError(t, err)
|
||||
|
||||
return store.NewStore(tmpdir), func() { os.RemoveAll(tmpdir) }
|
||||
}
|
||||
|
||||
func ref(t *testing.T, name string) reference.Named {
|
||||
named, err := reference.ParseNamed("example.com/" + name)
|
||||
assert.NilError(t, err)
|
||||
|
@ -70,22 +62,20 @@ func fullImageManifest(t *testing.T, ref reference.Named) types.ImageManifest {
|
|||
}
|
||||
|
||||
func TestInspectCommandLocalManifestNotFound(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
||||
cmd := newInspectCommand(cli)
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
|
||||
err := cmd.Execute()
|
||||
assert.Error(t, err, "No such manifest: example.com/alpine:3.0")
|
||||
}
|
||||
|
||||
func TestInspectCommandNotFound(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -99,15 +89,14 @@ func TestInspectCommandNotFound(t *testing.T) {
|
|||
})
|
||||
|
||||
cmd := newInspectCommand(cli)
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetArgs([]string{"example.com/alpine:3.0"})
|
||||
err := cmd.Execute()
|
||||
assert.Error(t, err, "No such manifest: example.com/alpine:3.0")
|
||||
}
|
||||
|
||||
func TestInspectCommandLocalManifest(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -125,8 +114,7 @@ func TestInspectCommandLocalManifest(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInspectcommandRemoteManifest(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -137,7 +125,7 @@ func TestInspectcommandRemoteManifest(t *testing.T) {
|
|||
})
|
||||
|
||||
cmd := newInspectCommand(cli)
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetArgs([]string{"example.com/alpine:3.0"})
|
||||
assert.NilError(t, cmd.Execute())
|
||||
actual := cli.OutBuffer()
|
||||
|
|
|
@ -2,9 +2,10 @@ package manifest
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/cli/manifest/store"
|
||||
manifesttypes "github.com/docker/cli/cli/manifest/types"
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/distribution/reference"
|
||||
|
@ -42,14 +43,13 @@ func TestManifestPushErrors(t *testing.T) {
|
|||
cli := test.NewFakeCli(nil)
|
||||
cmd := newPushListCommand(cli)
|
||||
cmd.SetArgs(tc.args)
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestPush(t *testing.T) {
|
||||
store, sCleanup := newTempManifestStore(t)
|
||||
defer sCleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
registry := newFakeRegistryClient()
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package manifest
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/cli/manifest/store"
|
||||
"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()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -31,7 +31,7 @@ func TestRmSeveralManifests(t *testing.T) {
|
|||
|
||||
cmd := newRmManifestListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
err = cmd.Execute()
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
@ -43,8 +43,7 @@ func TestRmSeveralManifests(t *testing.T) {
|
|||
|
||||
// attempt to remove a manifest list which was never created
|
||||
func TestRmManifestNotCreated(t *testing.T) {
|
||||
store, cleanup := newTempManifestStore(t)
|
||||
defer cleanup()
|
||||
store := store.NewStore(t.TempDir())
|
||||
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
|
@ -56,7 +55,7 @@ func TestRmManifestNotCreated(t *testing.T) {
|
|||
|
||||
cmd := newRmManifestListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"})
|
||||
cmd.SetOut(ioutil.Discard)
|
||||
cmd.SetOut(io.Discard)
|
||||
err = cmd.Execute()
|
||||
assert.Error(t, err, "No such manifest: example.com/first:1")
|
||||
|
||||
|
|
Loading…
Reference in New Issue