github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/cli/command/image/tag_test.go (about)

     1  package image
     2  
     3  import (
     4  	"io/ioutil"
     5  	"testing"
     6  
     7  	"github.com/docker/cli/internal/test"
     8  	"gotest.tools/assert"
     9  	is "gotest.tools/assert/cmp"
    10  )
    11  
    12  func TestCliNewTagCommandErrors(t *testing.T) {
    13  	testCases := [][]string{
    14  		{},
    15  		{"image1"},
    16  		{"image1", "image2", "image3"},
    17  	}
    18  	expectedError := "\"tag\" requires exactly 2 arguments."
    19  	for _, args := range testCases {
    20  		cmd := NewTagCommand(test.NewFakeCli(&fakeClient{}))
    21  		cmd.SetArgs(args)
    22  		cmd.SetOutput(ioutil.Discard)
    23  		assert.ErrorContains(t, cmd.Execute(), expectedError)
    24  	}
    25  }
    26  
    27  func TestCliNewTagCommand(t *testing.T) {
    28  	cmd := NewTagCommand(
    29  		test.NewFakeCli(&fakeClient{
    30  			imageTagFunc: func(image string, ref string) error {
    31  				assert.Check(t, is.Equal("image1", image))
    32  				assert.Check(t, is.Equal("image2", ref))
    33  				return nil
    34  			},
    35  		}))
    36  	cmd.SetArgs([]string{"image1", "image2"})
    37  	cmd.SetOutput(ioutil.Discard)
    38  	assert.NilError(t, cmd.Execute())
    39  	value, _ := cmd.Flags().GetBool("interspersed")
    40  	assert.Check(t, !value)
    41  }