Skip to content

Commit

Permalink
SQUASH: Address feedback
Browse files Browse the repository at this point in the history
* Change to use `assert.Contains`.
* Test Warning message.

Signed-off-by: Marcus Martins <marcus@docker.com>
  • Loading branch information
marcusmartins committed May 26, 2017
1 parent ddeca13 commit 6c11546
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cli/command/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"

. "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/stretchr/testify/require"
)

type fakeClient struct {
Expand All @@ -29,28 +29,33 @@ func (cli *fakeClient) Info(_ context.Context) (types.Info, error) {
func TestElectAuthServer(t *testing.T) {
testCases := []struct {
expectedAuthServer string
expectedWarning string
infoFunc func() (types.Info, error)
}{
{
expectedAuthServer: "https://index.docker.io/v1/",
expectedWarning: "",
infoFunc: func() (types.Info, error) {
return types.Info{IndexServerAddress: "https://index.docker.io/v1/"}, nil
},
},
{
expectedAuthServer: "https://index.docker.io/v1/",
expectedWarning: "Empty registry endpoint from daemon",
infoFunc: func() (types.Info, error) {
return types.Info{IndexServerAddress: ""}, nil
},
},
{
expectedAuthServer: "https://foo.bar",
expectedWarning: "",
infoFunc: func() (types.Info, error) {
return types.Info{IndexServerAddress: "https://foo.bar"}, nil
},
},
{
expectedAuthServer: "https://index.docker.io/v1/",
expectedWarning: "failed to get default registry endpoint from daemon",
infoFunc: func() (types.Info, error) {
return types.Info{}, errors.Errorf("error getting info")
},
Expand All @@ -59,7 +64,16 @@ func TestElectAuthServer(t *testing.T) {
for _, tc := range testCases {
buf := new(bytes.Buffer)
cli := test.NewFakeCli(&fakeClient{infoFunc: tc.infoFunc}, buf)
outBuf := new(bytes.Buffer)
cli.SetOut(outBuf)
server := ElectAuthServer(context.Background(), cli)
require.Equal(t, tc.expectedAuthServer, server)
assert.Equal(t, tc.expectedAuthServer, server)
actual := outBuf.String()
if tc.expectedWarning == "" {
assert.Empty(t, actual)
} else {
assert.Contains(t, actual, tc.expectedWarning)
}

}
}
5 changes: 5 additions & 0 deletions cli/internal/test/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (c *FakeCli) SetErr(err io.Writer) {
c.err = err
}

// SetOut sets the stderr stream for the cli to the specified io.Writer
func (c *FakeCli) SetOut(out io.Writer) {
c.out = command.NewOutStream(out)
}

// SetConfigfile sets the "fake" config file
func (c *FakeCli) SetConfigfile(configfile *configfile.ConfigFile) {
c.configfile = configfile
Expand Down

0 comments on commit 6c11546

Please sign in to comment.