2017-03-30 20:21:14 -04:00
|
|
|
package image
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-10-10 15:57:16 -04:00
|
|
|
"io"
|
2017-03-30 20:21:14 -04:00
|
|
|
"io/ioutil"
|
2017-10-10 15:57:16 -04:00
|
|
|
"strings"
|
2017-03-30 20:21:14 -04:00
|
|
|
"testing"
|
|
|
|
|
2017-08-21 16:30:09 -04:00
|
|
|
"github.com/docker/cli/internal/test"
|
2017-08-21 16:39:35 -04:00
|
|
|
"github.com/docker/cli/internal/test/testutil"
|
2017-10-10 15:57:16 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2017-08-16 12:19:53 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/golden"
|
2017-03-30 20:21:14 -04:00
|
|
|
"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",
|
2017-08-12 12:25:38 -04:00
|
|
|
expectedError: "requires exactly 1 argument.",
|
2017-03-30 20:21:14 -04:00
|
|
|
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"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
2017-07-05 14:34:16 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{})
|
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-10-10 15:57:16 -04:00
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectedTag string
|
2017-03-30 20:21:14 -04:00
|
|
|
}{
|
|
|
|
{
|
2017-10-10 15:57:16 -04:00
|
|
|
name: "simple",
|
|
|
|
args: []string{"image:tag"},
|
|
|
|
expectedTag: "image:tag",
|
2017-03-30 20:21:14 -04:00
|
|
|
},
|
|
|
|
{
|
2017-10-10 15:57:16 -04:00
|
|
|
name: "simple-no-tag",
|
|
|
|
args: []string{"image"},
|
|
|
|
expectedTag: "image:latest",
|
2017-03-30 20:21:14 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
2017-10-10 15:57:16 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
|
|
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
|
|
|
|
assert.Equal(t, tc.expectedTag, ref, tc.name)
|
|
|
|
return ioutil.NopCloser(strings.NewReader("")), nil
|
|
|
|
},
|
|
|
|
})
|
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)
|
2017-08-16 12:19:53 -04:00
|
|
|
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("pull-command-success.%s.golden", tc.name))
|
2017-03-30 20:21:14 -04:00
|
|
|
}
|
|
|
|
}
|