2017-03-30 20:21:14 -04:00
|
|
|
package image
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2017-06-21 17:20:49 -04:00
|
|
|
"github.com/docker/cli/cli/config/configfile"
|
2017-03-30 20:21:14 -04:00
|
|
|
"github.com/docker/cli/cli/internal/test"
|
|
|
|
"github.com/docker/docker/pkg/testutil"
|
|
|
|
"github.com/docker/docker/pkg/testutil/golden"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPullCommandErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2017-06-09 12:32:14 -04:00
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectedError string
|
2017-03-30 20:21:14 -04:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "wrong-args",
|
|
|
|
expectedError: "requires exactly 1 argument(s).",
|
|
|
|
args: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid-name",
|
|
|
|
expectedError: "invalid reference format: repository name must be lowercase",
|
|
|
|
args: []string{"UPPERCASE_REPO"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "all-tags-with-tag",
|
|
|
|
expectedError: "tag can't be used with --all-tags/-a",
|
|
|
|
args: []string{"--all-tags", "image:tag"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "pull-error",
|
|
|
|
args: []string{"--disable-content-trust=false", "image:tag"},
|
|
|
|
expectedError: "you are not authorized to perform this operation: server returned 401.",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
buf := new(bytes.Buffer)
|
2017-06-21 17:20:49 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{}, buf)
|
2017-06-27 10:31:38 -04:00
|
|
|
cli.SetConfigfile(configfile.New("filename"))
|
2017-06-21 17:20:49 -04:00
|
|
|
cmd := NewPullCommand(cli)
|
2017-03-30 20:21:14 -04:00
|
|
|
cmd.SetOutput(ioutil.Discard)
|
|
|
|
cmd.SetArgs(tc.args)
|
2017-04-25 19:24:07 -04:00
|
|
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewPullCommandSuccess(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2017-06-09 12:32:14 -04:00
|
|
|
name string
|
|
|
|
args []string
|
2017-03-30 20:21:14 -04:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "simple",
|
|
|
|
args: []string{"image:tag"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-no-tag",
|
|
|
|
args: []string{"image"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
buf := new(bytes.Buffer)
|
2017-06-21 17:20:49 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{}, buf)
|
2017-06-27 10:31:38 -04:00
|
|
|
cli.SetConfigfile(configfile.New("filename"))
|
2017-06-21 17:20:49 -04:00
|
|
|
cmd := NewPullCommand(cli)
|
2017-03-30 20:21:14 -04:00
|
|
|
cmd.SetOutput(ioutil.Discard)
|
|
|
|
cmd.SetArgs(tc.args)
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
actual := buf.String()
|
|
|
|
expected := string(golden.Get(t, []byte(actual), fmt.Sprintf("pull-command-success.%s.golden", tc.name))[:])
|
|
|
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, expected)
|
|
|
|
}
|
|
|
|
}
|