mirror of https://github.com/docker/cli.git
Fix test and lint failures
Split test cases. Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
bb795aa7af
commit
f27934376d
|
@ -10,85 +10,70 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemoveStack(t *testing.T) {
|
func fakeClientForRemoveStackTest(version string) *fakeClient {
|
||||||
allServices := []string{
|
allServices := []string{
|
||||||
objectName("foo", "service1"),
|
objectName("foo", "service1"),
|
||||||
objectName("foo", "service2"),
|
objectName("foo", "service2"),
|
||||||
objectName("bar", "service1"),
|
objectName("bar", "service1"),
|
||||||
objectName("bar", "service2"),
|
objectName("bar", "service2"),
|
||||||
}
|
}
|
||||||
allServiceIDs := buildObjectIDs(allServices)
|
|
||||||
|
|
||||||
allNetworks := []string{
|
allNetworks := []string{
|
||||||
objectName("foo", "network1"),
|
objectName("foo", "network1"),
|
||||||
objectName("bar", "network1"),
|
objectName("bar", "network1"),
|
||||||
}
|
}
|
||||||
allNetworkIDs := buildObjectIDs(allNetworks)
|
|
||||||
|
|
||||||
allSecrets := []string{
|
allSecrets := []string{
|
||||||
objectName("foo", "secret1"),
|
objectName("foo", "secret1"),
|
||||||
objectName("foo", "secret2"),
|
objectName("foo", "secret2"),
|
||||||
objectName("bar", "secret1"),
|
objectName("bar", "secret1"),
|
||||||
}
|
}
|
||||||
allSecretIDs := buildObjectIDs(allSecrets)
|
|
||||||
|
|
||||||
allConfigs := []string{
|
allConfigs := []string{
|
||||||
objectName("foo", "config1"),
|
objectName("foo", "config1"),
|
||||||
objectName("foo", "config2"),
|
objectName("foo", "config2"),
|
||||||
objectName("bar", "config1"),
|
objectName("bar", "config1"),
|
||||||
}
|
}
|
||||||
allConfigIDs := buildObjectIDs(allConfigs)
|
return &fakeClient{
|
||||||
|
version: version,
|
||||||
// Using API 1.24; removes services, networks, but doesn't remove configs and secrets
|
|
||||||
cli := &fakeClient{
|
|
||||||
version: "1.24",
|
|
||||||
services: allServices,
|
services: allServices,
|
||||||
networks: allNetworks,
|
networks: allNetworks,
|
||||||
secrets: allSecrets,
|
secrets: allSecrets,
|
||||||
configs: allConfigs,
|
configs: allConfigs,
|
||||||
}
|
}
|
||||||
cmd := newRemoveCommand(test.NewFakeCli(cli))
|
}
|
||||||
|
|
||||||
|
func TestRemoveStackVersion124DoesNotRemoveConfigsOrSecrets(t *testing.T) {
|
||||||
|
client := fakeClientForRemoveStackTest("1.24")
|
||||||
|
cmd := newRemoveCommand(test.NewFakeCli(client))
|
||||||
cmd.SetArgs([]string{"foo", "bar"})
|
cmd.SetArgs([]string{"foo", "bar"})
|
||||||
|
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, allServiceIDs, cli.removedServices)
|
assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
|
||||||
assert.Equal(t, allNetworkIDs, cli.removedNetworks)
|
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
|
||||||
assert.Nil(t, cli.removedSecrets)
|
assert.Nil(t, client.removedSecrets)
|
||||||
assert.Nil(t, cli.removedConfigs)
|
assert.Nil(t, client.removedConfigs)
|
||||||
|
}
|
||||||
|
|
||||||
// Using API 1.25; removes services, networks, but doesn't remove configs
|
func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
|
||||||
cli = &fakeClient{
|
client := fakeClientForRemoveStackTest("1.25")
|
||||||
version: "1.25",
|
cmd := newRemoveCommand(test.NewFakeCli(client))
|
||||||
services: allServices,
|
|
||||||
networks: allNetworks,
|
|
||||||
secrets: allSecrets,
|
|
||||||
configs: allConfigs,
|
|
||||||
}
|
|
||||||
cmd = newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
|
|
||||||
cmd.SetArgs([]string{"foo", "bar"})
|
cmd.SetArgs([]string{"foo", "bar"})
|
||||||
|
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, allServiceIDs, cli.removedServices)
|
assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
|
||||||
assert.Equal(t, allNetworkIDs, cli.removedNetworks)
|
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
|
||||||
assert.Equal(t, allSecretIDs, cli.removedSecrets)
|
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets)
|
||||||
assert.Nil(t, cli.removedConfigs)
|
assert.Nil(t, client.removedConfigs)
|
||||||
|
}
|
||||||
|
|
||||||
// Using API 1.30; removes services, networks, configs, and secrets
|
func TestRemoveStackVersion130RemovesEverything(t *testing.T) {
|
||||||
cli = &fakeClient{
|
client := fakeClientForRemoveStackTest("1.30")
|
||||||
version: "1.30",
|
cmd := newRemoveCommand(test.NewFakeCli(client))
|
||||||
services: allServices,
|
|
||||||
networks: allNetworks,
|
|
||||||
secrets: allSecrets,
|
|
||||||
configs: allConfigs,
|
|
||||||
}
|
|
||||||
cmd = newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
|
|
||||||
cmd.SetArgs([]string{"foo", "bar"})
|
cmd.SetArgs([]string{"foo", "bar"})
|
||||||
|
|
||||||
assert.NoError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, allServiceIDs, cli.removedServices)
|
assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
|
||||||
assert.Equal(t, allNetworkIDs, cli.removedNetworks)
|
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
|
||||||
assert.Equal(t, allSecretIDs, cli.removedSecrets)
|
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets)
|
||||||
assert.Equal(t, allConfigIDs, cli.removedConfigs)
|
assert.Equal(t, buildObjectIDs(client.configs), client.removedConfigs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveStackSkipEmpty(t *testing.T) {
|
func TestRemoveStackSkipEmpty(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue