2017-12-05 09:41:03 -05:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2017-12-05 09:41:03 -05:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-12-26 09:40:17 -05:00
|
|
|
|
2017-12-05 09:41:03 -05:00
|
|
|
"github.com/docker/cli/internal/test"
|
|
|
|
"github.com/docker/docker/api"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersionWithoutServer(t *testing.T) {
|
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
|
|
serverVersion: func(ctx context.Context) (types.Version, error) {
|
|
|
|
return types.Version{}, fmt.Errorf("no server")
|
|
|
|
},
|
|
|
|
})
|
|
|
|
cmd := NewVersionCommand(cli)
|
|
|
|
cmd.SetOutput(cli.Err())
|
2017-12-21 16:27:57 -05:00
|
|
|
assert.ErrorContains(t, cmd.Execute(), "no server")
|
|
|
|
out := cli.OutBuffer().String()
|
|
|
|
// TODO: use an assertion like e2e/image/build_test.go:assertBuildOutput()
|
|
|
|
// instead of contains/not contains
|
|
|
|
assert.Check(t, is.Contains(out, "Client:"))
|
|
|
|
assert.Assert(t, !strings.Contains(out, "Server:"), "actual: %s", out)
|
2017-12-05 09:41:03 -05:00
|
|
|
}
|
|
|
|
|
2017-12-21 16:27:57 -05:00
|
|
|
func fakeServerVersion(_ context.Context) (types.Version, error) {
|
2017-12-05 09:41:03 -05:00
|
|
|
return types.Version{
|
|
|
|
Version: "docker-dev",
|
|
|
|
APIVersion: api.DefaultVersion,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-12-26 09:40:17 -05:00
|
|
|
func TestVersionWithOrchestrator(t *testing.T) {
|
2018-04-25 08:24:46 -04:00
|
|
|
cli := test.NewFakeCli(&fakeClient{serverVersion: fakeServerVersion}, test.OrchestratorSwarm)
|
2017-12-05 09:41:03 -05:00
|
|
|
cmd := NewVersionCommand(cli)
|
2017-12-21 16:27:57 -05:00
|
|
|
assert.NilError(t, cmd.Execute())
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Contains(cleanTabs(cli.OutBuffer().String()), "Orchestrator: swarm"))
|
2017-12-05 09:41:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func cleanTabs(line string) string {
|
|
|
|
return strings.Join(strings.Fields(line), " ")
|
|
|
|
}
|