diff --git a/integration-cli/docker_api_swarm_config_test.go b/integration-cli/docker_api_swarm_config_test.go deleted file mode 100644 index c01d80ff7f..0000000000 --- a/integration-cli/docker_api_swarm_config_test.go +++ /dev/null @@ -1,123 +0,0 @@ -// +build !windows - -package main - -import ( - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/integration-cli/checker" - "github.com/go-check/check" - "golang.org/x/net/context" -) - -func (s *DockerSwarmSuite) TestAPISwarmConfigsEmptyList(c *check.C) { - d := s.AddDaemon(c, true, true) - - configs := d.ListConfigs(c) - c.Assert(configs, checker.NotNil) - c.Assert(len(configs), checker.Equals, 0, check.Commentf("configs: %#v", configs)) -} - -func (s *DockerSwarmSuite) TestAPISwarmConfigsCreate(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)) - - configs := d.ListConfigs(c) - c.Assert(len(configs), checker.Equals, 1, check.Commentf("configs: %#v", configs)) - name := configs[0].Spec.Annotations.Name - c.Assert(name, checker.Equals, testName, check.Commentf("configs: %s", name)) -} - -func (s *DockerSwarmSuite) TestAPISwarmConfigsDelete(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.ID, checker.Equals, id, check.Commentf("config: %v", config)) - - d.DeleteConfig(c, config.ID) - - cli, err := d.NewClient() - c.Assert(err, checker.IsNil) - defer cli.Close() - - _, _, err = cli.ConfigInspectWithRaw(context.Background(), id) - c.Assert(err.Error(), checker.Contains, "No such config") -} - -func (s *DockerSwarmSuite) TestAPISwarmConfigsUpdate(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{ - "test": "test1", - }, - }, - Data: []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id)) - - config := d.GetConfig(c, id) - c.Assert(config.ID, checker.Equals, id, check.Commentf("config: %v", config)) - - // test UpdateConfig with full ID - d.UpdateConfig(c, id, func(s *swarm.Config) { - s.Spec.Labels = map[string]string{ - "test": "test1", - } - }) - - config = d.GetConfig(c, id) - c.Assert(config.Spec.Labels["test"], checker.Equals, "test1", check.Commentf("config: %v", config)) - - // test UpdateConfig with full name - d.UpdateConfig(c, config.Spec.Name, func(s *swarm.Config) { - s.Spec.Labels = map[string]string{ - "test": "test2", - } - }) - - config = d.GetConfig(c, id) - c.Assert(config.Spec.Labels["test"], checker.Equals, "test2", check.Commentf("config: %v", config)) - - // test UpdateConfig with prefix ID - d.UpdateConfig(c, id[:1], func(s *swarm.Config) { - s.Spec.Labels = map[string]string{ - "test": "test3", - } - }) - - config = d.GetConfig(c, id) - c.Assert(config.Spec.Labels["test"], checker.Equals, "test3", check.Commentf("config: %v", config)) - - // test UpdateConfig in updating Data which is not supported in daemon - // this test will produce an error in func UpdateConfig - config = d.GetConfig(c, id) - config.Spec.Data = []byte("TESTINGDATA2") - - cli, err := d.NewClient() - c.Assert(err, checker.IsNil) - defer cli.Close() - - expected := "only updates to Labels are allowed" - - err = cli.ConfigUpdate(context.Background(), config.ID, config.Version, config.Spec) - c.Assert(err.Error(), checker.Contains, expected) -} diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 0d7c557fad..fa2a205953 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -9,6 +9,7 @@ import ( swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/swarm" + "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/skip" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -26,6 +27,11 @@ func TestConfigList(t *testing.T) { ctx := context.Background() + // This test case is ported from the original TestConfigsEmptyList + configs, err := client.ConfigList(ctx, types.ConfigListOptions{}) + require.NoError(t, err) + assert.Equal(t, len(configs), 0) + testName0 := "test0" testName1 := "test1" testNames := []string{testName0, testName1} @@ -100,3 +106,85 @@ func createConfig(ctx context.Context, t *testing.T, client client.APIClient, na assert.NotEqual(t, config.ID, "") return config.ID } + +func TestConfigsCreateAndDelete(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType != "linux") + + defer setupTest(t)() + d := swarm.NewSwarm(t, testEnv) + defer d.Stop(t) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) + require.NoError(t, err) + + ctx := context.Background() + + testName := "test_config" + + // This test case is ported from the original TestConfigsCreate + configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + + insp, _, err := client.ConfigInspectWithRaw(ctx, configID) + require.NoError(t, err) + assert.Equal(t, insp.Spec.Name, testName) + + // This test case is ported from the original TestConfigsDelete + err = client.ConfigRemove(ctx, configID) + require.NoError(t, err) + + insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + testutil.ErrorContains(t, err, "No such config") +} + +func TestConfigsUpdate(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType != "linux") + + defer setupTest(t)() + d := swarm.NewSwarm(t, testEnv) + defer d.Stop(t) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) + require.NoError(t, err) + + ctx := context.Background() + + testName := "test_config" + + // This test case is ported from the original TestConfigsCreate + configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + + insp, _, err := client.ConfigInspectWithRaw(ctx, configID) + require.NoError(t, err) + assert.Equal(t, insp.ID, configID) + + // test UpdateConfig with full ID + insp.Spec.Labels = map[string]string{"test": "test1"} + err = client.ConfigUpdate(ctx, configID, insp.Version, insp.Spec) + require.NoError(t, err) + + insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + require.NoError(t, err) + assert.Equal(t, insp.Spec.Labels["test"], "test1") + + // test UpdateConfig with full name + insp.Spec.Labels = map[string]string{"test": "test2"} + err = client.ConfigUpdate(ctx, testName, insp.Version, insp.Spec) + require.NoError(t, err) + + insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + require.NoError(t, err) + assert.Equal(t, insp.Spec.Labels["test"], "test2") + + // test UpdateConfig with prefix ID + insp.Spec.Labels = map[string]string{"test": "test3"} + err = client.ConfigUpdate(ctx, configID[:1], insp.Version, insp.Spec) + require.NoError(t, err) + + insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + require.NoError(t, err) + assert.Equal(t, insp.Spec.Labels["test"], "test3") + + // test UpdateConfig in updating Data which is not supported in daemon + // this test will produce an error in func UpdateConfig + insp.Spec.Data = []byte("TESTINGDATA2") + err = client.ConfigUpdate(ctx, configID, insp.Version, insp.Spec) + testutil.ErrorContains(t, err, "only updates to Labels are allowed") +}