use gotest.tools/fs for TestActivateExpiredLicenseDryRun

Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
This commit is contained in:
Andrew Hsu 2018-09-28 18:31:38 +00:00 committed by Tibor Vass
parent 5a97a93ae1
commit a7488d1bcd
1 changed files with 5 additions and 10 deletions

View File

@ -2,9 +2,6 @@ package engine
import ( import (
"fmt" "fmt"
"io/ioutil"
"os"
"path/filepath"
"testing" "testing"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
@ -12,6 +9,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/fs"
"gotest.tools/golden" "gotest.tools/golden"
) )
@ -51,12 +49,9 @@ func TestActivateBadLicense(t *testing.T) {
} }
func TestActivateExpiredLicenseDryRun(t *testing.T) { func TestActivateExpiredLicenseDryRun(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "license") dir := fs.NewDir(t, "license", fs.WithFile("docker.lic", expiredLicense, fs.WithMode(0644)))
assert.NilError(t, err) defer dir.Remove()
defer os.RemoveAll(tmpdir) filename := dir.Join("docker.lic")
filename := filepath.Join(tmpdir, "docker.lic")
err = ioutil.WriteFile(filename, []byte(expiredLicense), 0644)
assert.NilError(t, err)
isRoot = func() bool { return true } isRoot = func() bool { return true }
c := test.NewFakeCli(&verClient{client.Client{}, types.Version{}, nil}) c := test.NewFakeCli(&verClient{client.Client{}, types.Version{}, nil})
c.SetContainerizedEngineClient( c.SetContainerizedEngineClient(
@ -70,7 +65,7 @@ func TestActivateExpiredLicenseDryRun(t *testing.T) {
cmd.Flags().Set("license", filename) cmd.Flags().Set("license", filename)
cmd.Flags().Set("display-only", "true") cmd.Flags().Set("display-only", "true")
c.OutBuffer().Reset() c.OutBuffer().Reset()
err = cmd.Execute() err := cmd.Execute()
assert.NilError(t, err) assert.NilError(t, err)
golden.Assert(t, c.OutBuffer().String(), "expired-license-display-only.golden") golden.Assert(t, c.OutBuffer().String(), "expired-license-display-only.golden")
} }