mirror of https://github.com/docker/cli.git
Update swarm command tests to use the new golden
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
1dd742eac8
commit
3d68aa8416
|
@ -1,7 +1,6 @@
|
||||||
package swarm
|
package swarm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -9,8 +8,7 @@ import (
|
||||||
"github.com/docker/cli/cli/internal/test"
|
"github.com/docker/cli/cli/internal/test"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -65,14 +63,13 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
cmd := newInitCommand(
|
cmd := newInitCommand(
|
||||||
test.NewFakeCliWithOutput(&fakeClient{
|
test.NewFakeCli(&fakeClient{
|
||||||
swarmInitFunc: tc.swarmInitFunc,
|
swarmInitFunc: tc.swarmInitFunc,
|
||||||
swarmInspectFunc: tc.swarmInspectFunc,
|
swarmInspectFunc: tc.swarmInspectFunc,
|
||||||
swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,
|
swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,
|
||||||
nodeInspectFunc: tc.nodeInspectFunc,
|
nodeInspectFunc: tc.nodeInspectFunc,
|
||||||
}, buf))
|
}))
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
|
@ -112,20 +109,17 @@ func TestSwarmInit(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
cmd := newInitCommand(
|
|
||||||
test.NewFakeCliWithOutput(&fakeClient{
|
|
||||||
swarmInitFunc: tc.swarmInitFunc,
|
swarmInitFunc: tc.swarmInitFunc,
|
||||||
swarmInspectFunc: tc.swarmInspectFunc,
|
swarmInspectFunc: tc.swarmInspectFunc,
|
||||||
swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,
|
swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,
|
||||||
nodeInspectFunc: tc.nodeInspectFunc,
|
nodeInspectFunc: tc.nodeInspectFunc,
|
||||||
}, buf))
|
})
|
||||||
|
cmd := newInitCommand(cli)
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("init-%s.golden", tc.name))
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("init-%s.golden", tc.name))
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package swarm
|
package swarm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -49,12 +48,11 @@ func TestSwarmJoinErrors(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
cmd := newJoinCommand(
|
cmd := newJoinCommand(
|
||||||
test.NewFakeCliWithOutput(&fakeClient{
|
test.NewFakeCli(&fakeClient{
|
||||||
swarmJoinFunc: tc.swarmJoinFunc,
|
swarmJoinFunc: tc.swarmJoinFunc,
|
||||||
infoFunc: tc.infoFunc,
|
infoFunc: tc.infoFunc,
|
||||||
}, buf))
|
}))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
|
@ -91,13 +89,12 @@ func TestSwarmJoin(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
cmd := newJoinCommand(
|
|
||||||
test.NewFakeCliWithOutput(&fakeClient{
|
|
||||||
infoFunc: tc.infoFunc,
|
infoFunc: tc.infoFunc,
|
||||||
}, buf))
|
})
|
||||||
|
cmd := newJoinCommand(cli)
|
||||||
cmd.SetArgs([]string{"remote"})
|
cmd.SetArgs([]string{"remote"})
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), tc.expected)
|
assert.Equal(t, strings.TrimSpace(cli.OutBuffer().String()), tc.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package swarm
|
package swarm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -13,7 +12,7 @@ import (
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/cli/cli/internal/test/builders"
|
. "github.com/docker/cli/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -90,14 +89,13 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
cmd := newJoinTokenCommand(
|
|
||||||
test.NewFakeCliWithOutput(&fakeClient{
|
|
||||||
swarmInspectFunc: tc.swarmInspectFunc,
|
swarmInspectFunc: tc.swarmInspectFunc,
|
||||||
swarmUpdateFunc: tc.swarmUpdateFunc,
|
swarmUpdateFunc: tc.swarmUpdateFunc,
|
||||||
infoFunc: tc.infoFunc,
|
infoFunc: tc.infoFunc,
|
||||||
nodeInspectFunc: tc.nodeInspectFunc,
|
nodeInspectFunc: tc.nodeInspectFunc,
|
||||||
}, buf))
|
})
|
||||||
|
cmd := newJoinTokenCommand(cli)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
|
@ -198,20 +196,17 @@ func TestSwarmJoinToken(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
cmd := newJoinTokenCommand(
|
|
||||||
test.NewFakeCliWithOutput(&fakeClient{
|
|
||||||
swarmInspectFunc: tc.swarmInspectFunc,
|
swarmInspectFunc: tc.swarmInspectFunc,
|
||||||
infoFunc: tc.infoFunc,
|
infoFunc: tc.infoFunc,
|
||||||
nodeInspectFunc: tc.nodeInspectFunc,
|
nodeInspectFunc: tc.nodeInspectFunc,
|
||||||
}, buf))
|
})
|
||||||
|
cmd := newJoinTokenCommand(cli)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("jointoken-%s.golden", tc.name))
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("jointoken-%s.golden", tc.name))
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,4 @@ Successfully rotated manager join token.
|
||||||
To add a manager to this swarm, run the following command:
|
To add a manager to this swarm, run the following command:
|
||||||
|
|
||||||
docker swarm join --token manager-join-token 127.0.0.1
|
docker swarm join --token manager-join-token 127.0.0.1
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
To add a manager to this swarm, run the following command:
|
To add a manager to this swarm, run the following command:
|
||||||
|
|
||||||
docker swarm join --token manager-join-token 127.0.0.1
|
docker swarm join --token manager-join-token 127.0.0.1
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
To add a worker to this swarm, run the following command:
|
To add a worker to this swarm, run the following command:
|
||||||
|
|
||||||
docker swarm join --token worker-join-token 127.0.0.1
|
docker swarm join --token worker-join-token 127.0.0.1
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/cli/cli/internal/test/builders"
|
. "github.com/docker/cli/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -167,8 +167,6 @@ func TestSwarmUnlockKey(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("unlockkeys-%s.golden", tc.name))
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("unlockkeys-%s.golden", tc.name))
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/cli/cli/internal/test/builders"
|
. "github.com/docker/cli/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/gotestyourself/gotestyourself/golden"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -174,8 +174,6 @@ func TestSwarmUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
cmd.SetOutput(cli.OutBuffer())
|
cmd.SetOutput(cli.OutBuffer())
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := cli.OutBuffer().String()
|
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("update-%s.golden", tc.name))
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("update-%s.golden", tc.name))
|
|
||||||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue