From 0e57ceae0dd42491ed81538bf4d9164218080b66 Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Fri, 13 Jul 2018 17:29:02 -0400 Subject: [PATCH] moved integration tests from docker_cli_config_create_test.go to integration/config Signed-off-by: Arash Deshmeh --- .../docker_cli_config_create_test.go | 101 ------------------ integration/config/config_test.go | 99 +++++++++++++++-- 2 files changed, 88 insertions(+), 112 deletions(-) diff --git a/integration-cli/docker_cli_config_create_test.go b/integration-cli/docker_cli_config_create_test.go index 9bc108a587..c499a2c9cf 100644 --- a/integration-cli/docker_cli_config_create_test.go +++ b/integration-cli/docker_cli_config_create_test.go @@ -7,111 +7,10 @@ import ( "os" "strings" - "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" ) -func (s *DockerSwarmSuite) TestConfigCreate(c *check.C) { - d := s.AddDaemon(c, true, true) - - testName := "test_config" - id := d.CreateConfig(c, swarm.ConfigSpec{ - Annotations: swarm.Annotations{ - Name: testName, - }, - Data: []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id)) - - config := d.GetConfig(c, id) - c.Assert(config.Spec.Name, checker.Equals, testName) -} - -func (s *DockerSwarmSuite) TestConfigCreateWithLabels(c *check.C) { - d := s.AddDaemon(c, true, true) - - testName := "test_config" - id := d.CreateConfig(c, swarm.ConfigSpec{ - Annotations: swarm.Annotations{ - Name: testName, - Labels: map[string]string{ - "key1": "value1", - "key2": "value2", - }, - }, - Data: []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id)) - - config := d.GetConfig(c, id) - c.Assert(config.Spec.Name, checker.Equals, testName) - c.Assert(len(config.Spec.Labels), checker.Equals, 2) - c.Assert(config.Spec.Labels["key1"], checker.Equals, "value1") - c.Assert(config.Spec.Labels["key2"], checker.Equals, "value2") -} - -// Test case for 28884 -func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "test_config" - id := d.CreateConfig(c, swarm.ConfigSpec{ - Annotations: swarm.Annotations{ - Name: name, - }, - Data: []byte("foo"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id)) - - fake := d.CreateConfig(c, swarm.ConfigSpec{ - Annotations: swarm.Annotations{ - Name: id, - }, - Data: []byte("fake foo"), - }) - c.Assert(fake, checker.Not(checker.Equals), "", check.Commentf("configs: %s", fake)) - - out, err := d.Cmd("config", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - c.Assert(out, checker.Contains, fake) - - out, err = d.Cmd("config", "rm", id) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, id) - - // Fake one will remain - out, err = d.Cmd("config", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) - c.Assert(out, checker.Contains, fake) - - // Remove based on name prefix of the fake one - // (which is the same as the ID of foo one) should not work - // as search is only done based on: - // - Full ID - // - Full Name - // - Partial ID (prefix) - out, err = d.Cmd("config", "rm", id[:5]) - c.Assert(err, checker.Not(checker.IsNil)) - c.Assert(out, checker.Not(checker.Contains), id) - out, err = d.Cmd("config", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) - c.Assert(out, checker.Contains, fake) - - // Remove based on ID prefix of the fake one should succeed - out, err = d.Cmd("config", "rm", fake[:5]) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, fake[:5]) - out, err = d.Cmd("config", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) - c.Assert(out, checker.Not(checker.Contains), id) - c.Assert(out, checker.Not(checker.Contains), fake) -} - func (s *DockerSwarmSuite) TestConfigCreateWithFile(c *check.C) { d := s.AddDaemon(c, true, true) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 3cbca23899..536a645b01 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -45,19 +45,10 @@ func TestConfigList(t *testing.T) { config1ID := createConfig(ctx, t, client, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"}) - names := func(entries []swarmtypes.Config) []string { - var values []string - for _, entry := range entries { - values = append(values, entry.Spec.Name) - } - sort.Strings(values) - return values - } - // test by `config ls` entries, err := client.ConfigList(ctx, types.ConfigListOptions{}) assert.NilError(t, err) - assert.Check(t, is.DeepEqual(names(entries), testNames)) + assert.Check(t, is.DeepEqual(configNamesFromList(entries), testNames)) testCases := []struct { filters filters.Args @@ -92,7 +83,7 @@ func TestConfigList(t *testing.T) { Filters: tc.filters, }) assert.NilError(t, err) - assert.Check(t, is.DeepEqual(names(entries), tc.expected)) + assert.Check(t, is.DeepEqual(configNamesFromList(entries), tc.expected)) } } @@ -354,3 +345,89 @@ func TestConfigInspect(t *testing.T) { assert.NilError(t, err) assert.Check(t, is.DeepEqual(config, insp)) } + +func TestConfigCreateWithLabels(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType != "linux") + + defer setupTest(t)() + d := swarm.NewSwarm(t, testEnv) + defer d.Stop(t) + client := d.NewClientT(t) + defer client.Close() + + ctx := context.Background() + + labels := map[string]string{ + "key1": "value1", + "key2": "value2", + } + testName := t.Name() + configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), labels) + + insp, _, err := client.ConfigInspectWithRaw(ctx, configID) + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Name, testName)) + assert.Check(t, is.Equal(2, len(insp.Spec.Labels))) + assert.Check(t, is.Equal("value1", insp.Spec.Labels["key1"])) + assert.Check(t, is.Equal("value2", insp.Spec.Labels["key2"])) +} + +// Test case for 28884 +func TestConfigCreateResolve(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType != "linux") + + defer setupTest(t)() + d := swarm.NewSwarm(t, testEnv) + defer d.Stop(t) + client := d.NewClientT(t) + defer client.Close() + + ctx := context.Background() + + configName := "test_config_" + t.Name() + + configID := createConfig(ctx, t, client, configName, []byte("foo"), nil) + fakeName := configID + fakeID := createConfig(ctx, t, client, fakeName, []byte("fake foo"), nil) + + entries, err := client.ConfigList(ctx, types.ConfigListOptions{}) + assert.NilError(t, err) + assert.Assert(t, is.Contains(configNamesFromList(entries), configName)) + assert.Assert(t, is.Contains(configNamesFromList(entries), fakeName)) + + err = client.ConfigRemove(ctx, configID) + assert.NilError(t, err) + + // Fake one will remain + entries, err = client.ConfigList(ctx, types.ConfigListOptions{}) + assert.NilError(t, err) + assert.Assert(t, is.DeepEqual(configNamesFromList(entries), []string{fakeName})) + + // Remove based on name prefix of the fake one + // (which is the same as the ID of foo one) should not work + // as search is only done based on: + // - Full ID + // - Full Name + // - Partial ID (prefix) + err = client.ConfigRemove(ctx, configID[:5]) + assert.Assert(t, nil != err) + entries, err = client.ConfigList(ctx, types.ConfigListOptions{}) + assert.NilError(t, err) + assert.Assert(t, is.DeepEqual(configNamesFromList(entries), []string{fakeName})) + + // Remove based on ID prefix of the fake one should succeed + err = client.ConfigRemove(ctx, fakeID[:5]) + assert.NilError(t, err) + entries, err = client.ConfigList(ctx, types.ConfigListOptions{}) + assert.NilError(t, err) + assert.Assert(t, is.Equal(0, len(entries))) +} + +func configNamesFromList(entries []swarmtypes.Config) []string { + var values []string + for _, entry := range entries { + values = append(values, entry.Spec.Name) + } + sort.Strings(values) + return values +}