2018-02-27 06:14:07 -05:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2018-03-06 05:15:18 -05:00
|
|
|
"fmt"
|
2018-06-23 10:27:27 -04:00
|
|
|
"io/ioutil"
|
2018-02-27 06:14:07 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/cli/internal/test"
|
2018-03-06 05:15:18 -05:00
|
|
|
"github.com/docker/cli/internal/test/notary"
|
2018-02-27 06:14:07 -05:00
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/docker/docker/api/types/network"
|
2018-06-08 12:24:26 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2018-02-27 06:14:07 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRunLabel(t *testing.T) {
|
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
|
|
createContainerFunc: func(_ *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ string) (container.ContainerCreateCreatedBody, error) {
|
|
|
|
return container.ContainerCreateCreatedBody{
|
|
|
|
ID: "id",
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
Version: "1.36",
|
|
|
|
})
|
|
|
|
cmd := NewRunCommand(cli)
|
|
|
|
cmd.Flags().Set("detach", "true")
|
|
|
|
cmd.SetArgs([]string{"--label", "foo", "busybox"})
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, cmd.Execute())
|
2018-02-27 06:14:07 -05:00
|
|
|
}
|
2018-03-06 05:15:18 -05:00
|
|
|
|
|
|
|
func TestRunCommandWithContentTrustErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expectedError string
|
|
|
|
notaryFunc test.NotaryClientFuncType
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "offline-notary-server",
|
|
|
|
notaryFunc: notary.GetOfflineNotaryRepository,
|
|
|
|
expectedError: "client is offline",
|
|
|
|
args: []string{"image:tag"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "uninitialized-notary-server",
|
|
|
|
notaryFunc: notary.GetUninitializedNotaryRepository,
|
|
|
|
expectedError: "remote trust data does not exist",
|
|
|
|
args: []string{"image:tag"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty-notary-server",
|
|
|
|
notaryFunc: notary.GetEmptyTargetsNotaryRepository,
|
|
|
|
expectedError: "No valid trust data for tag",
|
|
|
|
args: []string{"image:tag"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
|
|
createContainerFunc: func(config *container.Config,
|
|
|
|
hostConfig *container.HostConfig,
|
|
|
|
networkingConfig *network.NetworkingConfig,
|
|
|
|
containerName string,
|
|
|
|
) (container.ContainerCreateCreatedBody, error) {
|
|
|
|
return container.ContainerCreateCreatedBody{}, fmt.Errorf("shouldn't try to pull image")
|
|
|
|
},
|
|
|
|
}, test.EnableContentTrust)
|
|
|
|
cli.SetNotaryClient(tc.notaryFunc)
|
|
|
|
cmd := NewRunCommand(cli)
|
|
|
|
cmd.SetArgs(tc.args)
|
2018-06-23 10:27:27 -04:00
|
|
|
cmd.SetOutput(ioutil.Discard)
|
2018-03-06 05:15:18 -05:00
|
|
|
err := cmd.Execute()
|
|
|
|
assert.Assert(t, err != nil)
|
|
|
|
assert.Assert(t, is.Contains(cli.ErrBuffer().String(), tc.expectedError))
|
|
|
|
}
|
|
|
|
}
|