From ec78112eddba9429769078d71d613c4de3f7216a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 14:16:18 +0200 Subject: [PATCH 01/13] integration/config: rename variables that collided with imported package name Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 100 +++++++++++++++--------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index ea6b87dd0f..530ba4e96b 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -29,13 +29,13 @@ func TestConfigList(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() // This test case is ported from the original TestConfigsEmptyList - configs, err := client.ConfigList(ctx, types.ConfigListOptions{}) + configs, err := c.ConfigList(ctx, types.ConfigListOptions{}) assert.NilError(t, err) assert.Check(t, is.Equal(len(configs), 0)) @@ -45,12 +45,12 @@ func TestConfigList(t *testing.T) { sort.Strings(testNames) // create config test0 - createConfig(ctx, t, client, testName0, []byte("TESTINGDATA0"), map[string]string{"type": "test"}) + createConfig(ctx, t, c, testName0, []byte("TESTINGDATA0"), map[string]string{"type": "test"}) - config1ID := createConfig(ctx, t, client, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"}) + config1ID := createConfig(ctx, t, c, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"}) // test by `config ls` - entries, err := client.ConfigList(ctx, types.ConfigListOptions{}) + entries, err := c.ConfigList(ctx, types.ConfigListOptions{}) assert.NilError(t, err) assert.Check(t, is.DeepEqual(configNamesFromList(entries), testNames)) @@ -83,7 +83,7 @@ func TestConfigList(t *testing.T) { }, } for _, tc := range testCases { - entries, err = client.ConfigList(ctx, types.ConfigListOptions{ + entries, err = c.ConfigList(ctx, types.ConfigListOptions{ Filters: tc.filters, }) assert.NilError(t, err) @@ -111,25 +111,25 @@ func TestConfigsCreateAndDelete(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName := "test_config-" + t.Name() // This test case is ported from the original TestConfigsCreate - configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - insp, _, err := client.ConfigInspectWithRaw(ctx, configID) + insp, _, err := c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Name, testName)) // This test case is ported from the original TestConfigsDelete - err = client.ConfigRemove(ctx, configID) + err = c.ConfigRemove(ctx, configID) assert.NilError(t, err) - insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + insp, _, err = c.ConfigInspectWithRaw(ctx, configID) assert.Check(t, is.ErrorContains(err, "No such config")) } @@ -139,51 +139,51 @@ func TestConfigsUpdate(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName := "test_config-" + t.Name() // This test case is ported from the original TestConfigsCreate - configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - insp, _, err := client.ConfigInspectWithRaw(ctx, configID) + insp, _, err := c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(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) + err = c.ConfigUpdate(ctx, configID, insp.Version, insp.Spec) assert.NilError(t, err) - insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + insp, _, err = c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(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) + err = c.ConfigUpdate(ctx, testName, insp.Version, insp.Spec) assert.NilError(t, err) - insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + insp, _, err = c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(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) + err = c.ConfigUpdate(ctx, configID[:1], insp.Version, insp.Spec) assert.NilError(t, err) - insp, _, err = client.ConfigInspectWithRaw(ctx, configID) + insp, _, err = c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(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) + err = c.ConfigUpdate(ctx, configID, insp.Version, insp.Spec) assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed")) } @@ -191,8 +191,8 @@ func TestTemplatedConfig(t *testing.T) { skip.If(t, testEnv.DaemonInfo.OSType == "windows") d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() referencedSecretName := "referencedsecret-" + t.Name() @@ -202,7 +202,7 @@ func TestTemplatedConfig(t *testing.T) { }, Data: []byte("this is a secret"), } - referencedSecret, err := client.SecretCreate(ctx, referencedSecretSpec) + referencedSecret, err := c.SecretCreate(ctx, referencedSecretSpec) assert.Check(t, err) referencedConfigName := "referencedconfig-" + t.Name() @@ -212,7 +212,7 @@ func TestTemplatedConfig(t *testing.T) { }, Data: []byte("this is a config"), } - referencedConfig, err := client.ConfigCreate(ctx, referencedConfigSpec) + referencedConfig, err := c.ConfigCreate(ctx, referencedConfigSpec) assert.Check(t, err) templatedConfigName := "templated_config-" + t.Name() @@ -228,7 +228,7 @@ func TestTemplatedConfig(t *testing.T) { "{{config \"referencedconfigtarget\"}}\n"), } - templatedConfig, err := client.ConfigCreate(ctx, configSpec) + templatedConfig, err := c.ConfigCreate(ctx, configSpec) assert.Check(t, err) serviceID := swarm.CreateService(t, d, @@ -273,7 +273,7 @@ func TestTemplatedConfig(t *testing.T) { var tasks []swarmtypes.Task getRunningTasks := func(log poll.LogT) poll.Result { - tasks = swarm.GetRunningTasks(t, client, serviceID) + tasks = swarm.GetRunningTasks(t, c, serviceID) if len(tasks) > 0 { return poll.Success() } @@ -284,7 +284,7 @@ func TestTemplatedConfig(t *testing.T) { task := tasks[0] getTask := func(log poll.LogT) poll.Result { if task.NodeID == "" || (task.Status.ContainerStatus == nil || task.Status.ContainerStatus.ContainerID == "") { - task, _, _ = client.TaskInspectWithRaw(context.Background(), task.ID) + task, _, _ = c.TaskInspectWithRaw(context.Background(), task.ID) } if task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" { return poll.Success() @@ -325,15 +325,15 @@ func TestConfigInspect(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName := t.Name() - configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - insp, body, err := client.ConfigInspectWithRaw(ctx, configID) + insp, body, err := c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Name, testName)) @@ -349,8 +349,8 @@ func TestConfigCreateWithLabels(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() @@ -359,9 +359,9 @@ func TestConfigCreateWithLabels(t *testing.T) { "key2": "value2", } testName := t.Name() - configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), labels) + configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), labels) - insp, _, err := client.ConfigInspectWithRaw(ctx, configID) + insp, _, err := c.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))) @@ -376,27 +376,27 @@ func TestConfigCreateResolve(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() configName := "test_config_" + t.Name() - configID := createConfig(ctx, t, client, configName, []byte("foo"), nil) + configID := createConfig(ctx, t, c, configName, []byte("foo"), nil) fakeName := configID - fakeID := createConfig(ctx, t, client, fakeName, []byte("fake foo"), nil) + fakeID := createConfig(ctx, t, c, fakeName, []byte("fake foo"), nil) - entries, err := client.ConfigList(ctx, types.ConfigListOptions{}) + entries, err := c.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) + err = c.ConfigRemove(ctx, configID) assert.NilError(t, err) // Fake one will remain - entries, err = client.ConfigList(ctx, types.ConfigListOptions{}) + entries, err = c.ConfigList(ctx, types.ConfigListOptions{}) assert.NilError(t, err) assert.Assert(t, is.DeepEqual(configNamesFromList(entries), []string{fakeName})) @@ -406,16 +406,16 @@ func TestConfigCreateResolve(t *testing.T) { // - Full ID // - Full Name // - Partial ID (prefix) - err = client.ConfigRemove(ctx, configID[:5]) + err = c.ConfigRemove(ctx, configID[:5]) assert.Assert(t, nil != err) - entries, err = client.ConfigList(ctx, types.ConfigListOptions{}) + entries, err = c.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]) + err = c.ConfigRemove(ctx, fakeID[:5]) assert.NilError(t, err) - entries, err = client.ConfigList(ctx, types.ConfigListOptions{}) + entries, err = c.ConfigList(ctx, types.ConfigListOptions{}) assert.NilError(t, err) assert.Assert(t, is.Equal(0, len(entries))) } From dd67b4794ee79a5b72be1f4cbb48b7b0829ec4ee Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 14:40:38 +0200 Subject: [PATCH 02/13] integration/config: TestTemplatedConfig: simplify task code Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 530ba4e96b..f6755e3fb4 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -271,29 +271,12 @@ func TestTemplatedConfig(t *testing.T) { swarm.ServiceWithName("svc"), ) - var tasks []swarmtypes.Task - getRunningTasks := func(log poll.LogT) poll.Result { - tasks = swarm.GetRunningTasks(t, c, serviceID) - if len(tasks) > 0 { - return poll.Success() - } - return poll.Continue("task still waiting") - } - poll.WaitOn(t, getRunningTasks, swarm.ServicePoll, poll.WithTimeout(1*time.Minute)) + poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, 1), swarm.ServicePoll, poll.WithTimeout(1*time.Minute)) - task := tasks[0] - getTask := func(log poll.LogT) poll.Result { - if task.NodeID == "" || (task.Status.ContainerStatus == nil || task.Status.ContainerStatus.ContainerID == "") { - task, _, _ = c.TaskInspectWithRaw(context.Background(), task.ID) - } - if task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" { - return poll.Success() - } - return poll.Continue("task still waiting") - } - poll.WaitOn(t, getTask, swarm.ServicePoll, poll.WithTimeout(1*time.Minute)) + tasks := swarm.GetRunningTasks(t, c, serviceID) + assert.Assert(t, len(tasks) > 0, "no running tasks found for service %s", serviceID) - attach := swarm.ExecTask(t, d, task, types.ExecConfig{ + attach := swarm.ExecTask(t, d, tasks[0], types.ExecConfig{ Cmd: []string{"/bin/cat", "/" + templatedConfigName}, AttachStdout: true, AttachStderr: true, @@ -304,7 +287,7 @@ func TestTemplatedConfig(t *testing.T) { "this is a config\n" assertAttachedStream(t, attach, expect) - attach = swarm.ExecTask(t, d, task, types.ExecConfig{ + attach = swarm.ExecTask(t, d, tasks[0], types.ExecConfig{ Cmd: []string{"mount"}, AttachStdout: true, AttachStderr: true, From de7866318128d710048d9800104bc4b6e133286e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 14:48:02 +0200 Subject: [PATCH 03/13] integration/secret: rename variables that collided with imported package name Signed-off-by: Sebastiaan van Stijn --- integration/secret/secret_test.go | 98 +++++++++++++++---------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 1ce11d0496..f6975d5ff1 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -24,19 +24,19 @@ func TestSecretInspect(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName := "test_secret_" + t.Name() - secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + secretID := createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - secret, _, err := client.SecretInspectWithRaw(context.Background(), secretID) + secret, _, err := c.SecretInspectWithRaw(context.Background(), secretID) assert.NilError(t, err) assert.Check(t, is.Equal(secret.Spec.Name, testName)) - secret, _, err = client.SecretInspectWithRaw(context.Background(), testName) + secret, _, err = c.SecretInspectWithRaw(context.Background(), testName) assert.NilError(t, err) assert.Check(t, is.Equal(secretID, secretID)) } @@ -47,8 +47,8 @@ func TestSecretList(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName0 := "test0_" + t.Name() @@ -57,13 +57,13 @@ func TestSecretList(t *testing.T) { sort.Strings(testNames) // create secret test0 - createSecret(ctx, t, client, testName0, []byte("TESTINGDATA0"), map[string]string{"type": "test"}) + createSecret(ctx, t, c, testName0, []byte("TESTINGDATA0"), map[string]string{"type": "test"}) // create secret test1 - secret1ID := createSecret(ctx, t, client, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"}) + secret1ID := createSecret(ctx, t, c, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"}) // test by `secret ls` - entries, err := client.SecretList(ctx, types.SecretListOptions{}) + entries, err := c.SecretList(ctx, types.SecretListOptions{}) assert.NilError(t, err) assert.Check(t, is.DeepEqual(secretNamesFromList(entries), testNames)) @@ -96,7 +96,7 @@ func TestSecretList(t *testing.T) { }, } for _, tc := range testCases { - entries, err = client.SecretList(ctx, types.SecretListOptions{ + entries, err = c.SecretList(ctx, types.SecretListOptions{ Filters: tc.filters, }) assert.NilError(t, err) @@ -124,15 +124,15 @@ func TestSecretsCreateAndDelete(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName := "test_secret_" + t.Name() - secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + secretID := createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), nil) // create an already existin secret, daemon should return a status code of 409 - _, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{ + _, err := c.SecretCreate(ctx, swarmtypes.SecretSpec{ Annotations: swarmtypes.Annotations{ Name: testName, }, @@ -141,23 +141,23 @@ func TestSecretsCreateAndDelete(t *testing.T) { assert.Check(t, is.ErrorContains(err, "already exists")) // Ported from original TestSecretsDelete - err = client.SecretRemove(ctx, secretID) + err = c.SecretRemove(ctx, secretID) assert.NilError(t, err) - _, _, err = client.SecretInspectWithRaw(ctx, secretID) + _, _, err = c.SecretInspectWithRaw(ctx, secretID) assert.Check(t, is.ErrorContains(err, "No such secret")) - err = client.SecretRemove(ctx, "non-existin") + err = c.SecretRemove(ctx, "non-existin") assert.Check(t, is.ErrorContains(err, "No such secret: non-existin")) // Ported from original TestSecretsCreteaWithLabels testName = "test_secret_with_labels_" + t.Name() - secretID = createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), map[string]string{ + secretID = createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), map[string]string{ "key1": "value1", "key2": "value2", }) - insp, _, err := client.SecretInspectWithRaw(ctx, secretID) + insp, _, err := c.SecretInspectWithRaw(ctx, secretID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Name, testName)) assert.Check(t, is.Equal(len(insp.Spec.Labels), 2)) @@ -171,48 +171,48 @@ func TestSecretsUpdate(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName := "test_secret_" + t.Name() - secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil) + secretID := createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - insp, _, err := client.SecretInspectWithRaw(ctx, secretID) + insp, _, err := c.SecretInspectWithRaw(ctx, secretID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.ID, secretID)) // test UpdateSecret with full ID insp.Spec.Labels = map[string]string{"test": "test1"} - err = client.SecretUpdate(ctx, secretID, insp.Version, insp.Spec) + err = c.SecretUpdate(ctx, secretID, insp.Version, insp.Spec) assert.NilError(t, err) - insp, _, err = client.SecretInspectWithRaw(ctx, secretID) + insp, _, err = c.SecretInspectWithRaw(ctx, secretID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test1")) // test UpdateSecret with full name insp.Spec.Labels = map[string]string{"test": "test2"} - err = client.SecretUpdate(ctx, testName, insp.Version, insp.Spec) + err = c.SecretUpdate(ctx, testName, insp.Version, insp.Spec) assert.NilError(t, err) - insp, _, err = client.SecretInspectWithRaw(ctx, secretID) + insp, _, err = c.SecretInspectWithRaw(ctx, secretID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test2")) // test UpdateSecret with prefix ID insp.Spec.Labels = map[string]string{"test": "test3"} - err = client.SecretUpdate(ctx, secretID[:1], insp.Version, insp.Spec) + err = c.SecretUpdate(ctx, secretID[:1], insp.Version, insp.Spec) assert.NilError(t, err) - insp, _, err = client.SecretInspectWithRaw(ctx, secretID) + insp, _, err = c.SecretInspectWithRaw(ctx, secretID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test3")) // test UpdateSecret in updating Data which is not supported in daemon // this test will produce an error in func UpdateSecret insp.Spec.Data = []byte("TESTINGDATA2") - err = client.SecretUpdate(ctx, secretID, insp.Version, insp.Spec) + err = c.SecretUpdate(ctx, secretID, insp.Version, insp.Spec) assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed")) } @@ -220,8 +220,8 @@ func TestTemplatedSecret(t *testing.T) { skip.If(t, testEnv.DaemonInfo.OSType == "windows") d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() referencedSecretName := "referencedsecret_" + t.Name() @@ -231,7 +231,7 @@ func TestTemplatedSecret(t *testing.T) { }, Data: []byte("this is a secret"), } - referencedSecret, err := client.SecretCreate(ctx, referencedSecretSpec) + referencedSecret, err := c.SecretCreate(ctx, referencedSecretSpec) assert.Check(t, err) referencedConfigName := "referencedconfig_" + t.Name() @@ -241,7 +241,7 @@ func TestTemplatedSecret(t *testing.T) { }, Data: []byte("this is a config"), } - referencedConfig, err := client.ConfigCreate(ctx, referencedConfigSpec) + referencedConfig, err := c.ConfigCreate(ctx, referencedConfigSpec) assert.Check(t, err) templatedSecretName := "templated_secret_" + t.Name() @@ -257,7 +257,7 @@ func TestTemplatedSecret(t *testing.T) { "{{config \"referencedconfigtarget\"}}\n"), } - templatedSecret, err := client.SecretCreate(ctx, secretSpec) + templatedSecret, err := c.SecretCreate(ctx, secretSpec) assert.Check(t, err) serviceName := "svc_" + t.Name() @@ -303,14 +303,14 @@ func TestTemplatedSecret(t *testing.T) { var tasks []swarmtypes.Task waitAndAssert(t, 60*time.Second, func(t *testing.T) bool { - tasks = swarm.GetRunningTasks(t, client, serviceID) + tasks = swarm.GetRunningTasks(t, c, serviceID) return len(tasks) > 0 }) task := tasks[0] waitAndAssert(t, 60*time.Second, func(t *testing.T) bool { if task.NodeID == "" || (task.Status.ContainerStatus == nil || task.Status.ContainerStatus.ContainerID == "") { - task, _, _ = client.TaskInspectWithRaw(context.Background(), task.ID) + task, _, _ = c.TaskInspectWithRaw(context.Background(), task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" }) @@ -341,27 +341,27 @@ func TestSecretCreateResolve(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client := d.NewClientT(t) - defer client.Close() + c := d.NewClientT(t) + defer c.Close() ctx := context.Background() testName := "test_secret_" + t.Name() - secretID := createSecret(ctx, t, client, testName, []byte("foo"), nil) + secretID := createSecret(ctx, t, c, testName, []byte("foo"), nil) fakeName := secretID - fakeID := createSecret(ctx, t, client, fakeName, []byte("fake foo"), nil) + fakeID := createSecret(ctx, t, c, fakeName, []byte("fake foo"), nil) - entries, err := client.SecretList(ctx, types.SecretListOptions{}) + entries, err := c.SecretList(ctx, types.SecretListOptions{}) assert.NilError(t, err) assert.Check(t, is.Contains(secretNamesFromList(entries), testName)) assert.Check(t, is.Contains(secretNamesFromList(entries), fakeName)) - err = client.SecretRemove(ctx, secretID) + err = c.SecretRemove(ctx, secretID) assert.NilError(t, err) // Fake one will remain - entries, err = client.SecretList(ctx, types.SecretListOptions{}) + entries, err = c.SecretList(ctx, types.SecretListOptions{}) assert.NilError(t, err) assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName})) @@ -370,16 +370,16 @@ func TestSecretCreateResolve(t *testing.T) { // - Full ID // - Full Name // - Partial ID (prefix) - err = client.SecretRemove(ctx, fakeName[:5]) + err = c.SecretRemove(ctx, fakeName[:5]) assert.Assert(t, nil != err) - entries, err = client.SecretList(ctx, types.SecretListOptions{}) + entries, err = c.SecretList(ctx, types.SecretListOptions{}) assert.NilError(t, err) assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName})) // Remove based on ID prefix of the fake one should succeed - err = client.SecretRemove(ctx, fakeID[:5]) + err = c.SecretRemove(ctx, fakeID[:5]) assert.NilError(t, err) - entries, err = client.SecretList(ctx, types.SecretListOptions{}) + entries, err = c.SecretList(ctx, types.SecretListOptions{}) assert.NilError(t, err) assert.Assert(t, is.Equal(0, len(entries))) } From 3c6f018f9489ba8ce48b9dfb50efca59616f78c4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 14:57:21 +0200 Subject: [PATCH 04/13] integration/secret: TestTemplatedSecret: simplify task code Signed-off-by: Sebastiaan van Stijn --- integration/secret/secret_test.go | 36 ++++++------------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index f6975d5ff1..6917fd993b 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -15,6 +15,7 @@ import ( "github.com/docker/docker/pkg/stdcopy" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" + "gotest.tools/v3/poll" "gotest.tools/v3/skip" ) @@ -301,21 +302,12 @@ func TestTemplatedSecret(t *testing.T) { swarm.ServiceWithName(serviceName), ) - var tasks []swarmtypes.Task - waitAndAssert(t, 60*time.Second, func(t *testing.T) bool { - tasks = swarm.GetRunningTasks(t, c, serviceID) - return len(tasks) > 0 - }) + poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, 1), swarm.ServicePoll, poll.WithTimeout(1*time.Minute)) - task := tasks[0] - waitAndAssert(t, 60*time.Second, func(t *testing.T) bool { - if task.NodeID == "" || (task.Status.ContainerStatus == nil || task.Status.ContainerStatus.ContainerID == "") { - task, _, _ = c.TaskInspectWithRaw(context.Background(), task.ID) - } - return task.NodeID != "" && task.Status.ContainerStatus != nil && task.Status.ContainerStatus.ContainerID != "" - }) + tasks := swarm.GetRunningTasks(t, c, serviceID) + assert.Assert(t, len(tasks) > 0, "no running tasks found for service %s", serviceID) - attach := swarm.ExecTask(t, d, task, types.ExecConfig{ + attach := swarm.ExecTask(t, d, tasks[0], types.ExecConfig{ Cmd: []string{"/bin/cat", "/run/secrets/templated_secret"}, AttachStdout: true, AttachStderr: true, @@ -326,7 +318,7 @@ func TestTemplatedSecret(t *testing.T) { "this is a config\n" assertAttachedStream(t, attach, expect) - attach = swarm.ExecTask(t, d, task, types.ExecConfig{ + attach = swarm.ExecTask(t, d, tasks[0], types.ExecConfig{ Cmd: []string{"mount"}, AttachStdout: true, AttachStderr: true, @@ -391,22 +383,6 @@ func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect st assert.Check(t, is.Contains(buf.String(), expect)) } -func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool) { - t.Helper() - after := time.After(timeout) - for { - select { - case <-after: - t.Fatal("timed out waiting for condition") - default: - } - if f(t) { - return - } - time.Sleep(100 * time.Millisecond) - } -} - func secretNamesFromList(entries []swarmtypes.Secret) []string { var values []string for _, entry := range entries { From 25424cf7722ca6da3b4c7f667ec83a6d0e63fd1b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 15:11:48 +0200 Subject: [PATCH 05/13] integration/config: move functions to be in line with "secret" tests Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index f6755e3fb4..b672b6462b 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -23,6 +23,30 @@ import ( "gotest.tools/v3/skip" ) +func TestConfigInspect(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType == "windows") + + defer setupTest(t)() + d := swarm.NewSwarm(t, testEnv) + defer d.Stop(t) + c := d.NewClientT(t) + defer c.Close() + + ctx := context.Background() + + testName := t.Name() + configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) + + insp, body, err := c.ConfigInspectWithRaw(ctx, configID) + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Name, testName)) + + var config swarmtypes.Config + err = json.Unmarshal(body, &config) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(config, insp)) +} + func TestConfigList(t *testing.T) { skip.If(t, testEnv.DaemonInfo.OSType == "windows") @@ -302,30 +326,6 @@ func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect st assert.Check(t, is.Contains(buf.String(), expect)) } -func TestConfigInspect(t *testing.T) { - skip.If(t, testEnv.DaemonInfo.OSType == "windows") - - defer setupTest(t)() - d := swarm.NewSwarm(t, testEnv) - defer d.Stop(t) - c := d.NewClientT(t) - defer c.Close() - - ctx := context.Background() - - testName := t.Name() - configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - - insp, body, err := c.ConfigInspectWithRaw(ctx, configID) - assert.NilError(t, err) - assert.Check(t, is.Equal(insp.Spec.Name, testName)) - - var config swarmtypes.Config - err = json.Unmarshal(body, &config) - assert.NilError(t, err) - assert.Check(t, is.DeepEqual(config, insp)) -} - func TestConfigCreateWithLabels(t *testing.T) { skip.If(t, testEnv.DaemonInfo.OSType != "linux") From a45c89ecd1ce41ce2c95b0fac39e7fe217711f25 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 15:18:42 +0200 Subject: [PATCH 06/13] integration/secret: fix TestSecretInspect not actually checking response Signed-off-by: Sebastiaan van Stijn --- integration/secret/secret_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 6917fd993b..48e311c213 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -3,6 +3,7 @@ package secret // import "github.com/docker/docker/integration/secret" import ( "bytes" "context" + "encoding/json" "sort" "testing" "time" @@ -30,16 +31,17 @@ func TestSecretInspect(t *testing.T) { ctx := context.Background() - testName := "test_secret_" + t.Name() + testName := t.Name() secretID := createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - secret, _, err := c.SecretInspectWithRaw(context.Background(), secretID) + insp, body, err := c.SecretInspectWithRaw(ctx, secretID) assert.NilError(t, err) - assert.Check(t, is.Equal(secret.Spec.Name, testName)) + assert.Check(t, is.Equal(insp.Spec.Name, testName)) - secret, _, err = c.SecretInspectWithRaw(context.Background(), testName) + var secret swarmtypes.Secret + err = json.Unmarshal(body, &secret) assert.NilError(t, err) - assert.Check(t, is.Equal(secretID, secretID)) + assert.Check(t, is.DeepEqual(secret, insp)) } func TestSecretList(t *testing.T) { From 348f412d850eea85541e57f5545ae3719931da5a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 15:23:49 +0200 Subject: [PATCH 07/13] integration: sync minor changes between config and secret tests Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 32 ++++++++++++++----------------- integration/secret/secret_test.go | 2 -- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index b672b6462b..277394f642 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -55,7 +55,6 @@ func TestConfigList(t *testing.T) { defer d.Stop(t) c := d.NewClientT(t) defer c.Close() - ctx := context.Background() // This test case is ported from the original TestConfigsEmptyList @@ -137,7 +136,6 @@ func TestConfigsCreateAndDelete(t *testing.T) { defer d.Stop(t) c := d.NewClientT(t) defer c.Close() - ctx := context.Background() testName := "test_config-" + t.Name() @@ -165,12 +163,9 @@ func TestConfigsUpdate(t *testing.T) { defer d.Stop(t) c := d.NewClientT(t) defer c.Close() - ctx := context.Background() testName := "test_config-" + t.Name() - - // This test case is ported from the original TestConfigsCreate configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) insp, _, err := c.ConfigInspectWithRaw(ctx, configID) @@ -255,11 +250,12 @@ func TestTemplatedConfig(t *testing.T) { templatedConfig, err := c.ConfigCreate(ctx, configSpec) assert.Check(t, err) + serviceName := "svc_" + t.Name() serviceID := swarm.CreateService(t, d, swarm.ServiceWithConfig( &swarmtypes.ConfigReference{ File: &swarmtypes.ConfigReferenceFileTarget{ - Name: "/" + templatedConfigName, + Name: "templated_config", UID: "0", GID: "0", Mode: 0600, @@ -292,7 +288,7 @@ func TestTemplatedConfig(t *testing.T) { SecretName: referencedSecretName, }, ), - swarm.ServiceWithName("svc"), + swarm.ServiceWithName(serviceName), ) poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, 1), swarm.ServicePoll, poll.WithTimeout(1*time.Minute)) @@ -301,12 +297,12 @@ func TestTemplatedConfig(t *testing.T) { assert.Assert(t, len(tasks) > 0, "no running tasks found for service %s", serviceID) attach := swarm.ExecTask(t, d, tasks[0], types.ExecConfig{ - Cmd: []string{"/bin/cat", "/" + templatedConfigName}, + Cmd: []string{"/bin/cat", "/templated_config"}, AttachStdout: true, AttachStderr: true, }) - expect := "SERVICE_NAME=svc\n" + + expect := "SERVICE_NAME=" + serviceName + "\n" + "this is a secret\n" + "this is a config\n" assertAttachedStream(t, attach, expect) @@ -316,14 +312,7 @@ func TestTemplatedConfig(t *testing.T) { AttachStdout: true, AttachStderr: true, }) - assertAttachedStream(t, attach, "tmpfs on /"+templatedConfigName+" type tmpfs") -} - -func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect string) { - buf := bytes.NewBuffer(nil) - _, err := stdcopy.StdCopy(buf, buf, attach.Reader) - assert.NilError(t, err) - assert.Check(t, is.Contains(buf.String(), expect)) + assertAttachedStream(t, attach, "tmpfs on /templated_config type tmpfs") } func TestConfigCreateWithLabels(t *testing.T) { @@ -365,8 +354,8 @@ func TestConfigCreateResolve(t *testing.T) { ctx := context.Background() configName := "test_config_" + t.Name() - configID := createConfig(ctx, t, c, configName, []byte("foo"), nil) + fakeName := configID fakeID := createConfig(ctx, t, c, fakeName, []byte("fake foo"), nil) @@ -423,6 +412,13 @@ func TestConfigDaemonLibtrustID(t *testing.T) { assert.Equal(t, info.ID, "WTJ3:YSIP:CE2E:G6KJ:PSBD:YX2Y:WEYD:M64G:NU2V:XPZV:H2CR:VLUB") } +func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect string) { + buf := bytes.NewBuffer(nil) + _, err := stdcopy.StdCopy(buf, buf, attach.Reader) + assert.NilError(t, err) + assert.Check(t, is.Contains(buf.String(), expect)) +} + func configNamesFromList(entries []swarmtypes.Config) []string { var values []string for _, entry := range entries { diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 48e311c213..65042a7dc9 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -143,7 +143,6 @@ func TestSecretsCreateAndDelete(t *testing.T) { }) assert.Check(t, is.ErrorContains(err, "already exists")) - // Ported from original TestSecretsDelete err = c.SecretRemove(ctx, secretID) assert.NilError(t, err) @@ -153,7 +152,6 @@ func TestSecretsCreateAndDelete(t *testing.T) { err = c.SecretRemove(ctx, "non-existin") assert.Check(t, is.ErrorContains(err, "No such secret: non-existin")) - // Ported from original TestSecretsCreteaWithLabels testName = "test_secret_with_labels_" + t.Name() secretID = createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), map[string]string{ "key1": "value1", From 18cae89436ecdb8871567ce333d5c5bb1151fba3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 15:33:48 +0200 Subject: [PATCH 08/13] integration/config: don't string-match errors Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 277394f642..1c4580ee5b 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -14,6 +14,7 @@ import ( "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" + "github.com/docker/docker/errdefs" "github.com/docker/docker/integration/internal/swarm" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/testutil/daemon" @@ -151,8 +152,9 @@ func TestConfigsCreateAndDelete(t *testing.T) { err = c.ConfigRemove(ctx, configID) assert.NilError(t, err) - insp, _, err = c.ConfigInspectWithRaw(ctx, configID) - assert.Check(t, is.ErrorContains(err, "No such config")) + _, _, err = c.ConfigInspectWithRaw(ctx, configID) + assert.Check(t, errdefs.IsNotFound(err)) + assert.Check(t, is.ErrorContains(err, configID)) } func TestConfigsUpdate(t *testing.T) { @@ -203,6 +205,7 @@ func TestConfigsUpdate(t *testing.T) { // this test will produce an error in func UpdateConfig insp.Spec.Data = []byte("TESTINGDATA2") err = c.ConfigUpdate(ctx, configID, insp.Version, insp.Spec) + assert.Check(t, errdefs.IsInvalidParameter(err)) assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed")) } From 3c4b258f21f34c57d980c6ebd1633ecabe2dd5b6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 15:50:32 +0200 Subject: [PATCH 09/13] integration/secret: don't string-match errors Signed-off-by: Sebastiaan van Stijn --- integration/secret/secret_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 65042a7dc9..564b9c28fd 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" + "github.com/docker/docker/errdefs" "github.com/docker/docker/integration/internal/swarm" "github.com/docker/docker/pkg/stdcopy" "gotest.tools/v3/assert" @@ -134,23 +135,26 @@ func TestSecretsCreateAndDelete(t *testing.T) { testName := "test_secret_" + t.Name() secretID := createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - // create an already existin secret, daemon should return a status code of 409 + // create an already existing secret, daemon should return a status code of 409 _, err := c.SecretCreate(ctx, swarmtypes.SecretSpec{ Annotations: swarmtypes.Annotations{ Name: testName, }, Data: []byte("TESTINGDATA"), }) - assert.Check(t, is.ErrorContains(err, "already exists")) + assert.Check(t, errdefs.IsConflict(err)) + assert.Check(t, is.ErrorContains(err, testName)) err = c.SecretRemove(ctx, secretID) assert.NilError(t, err) _, _, err = c.SecretInspectWithRaw(ctx, secretID) - assert.Check(t, is.ErrorContains(err, "No such secret")) + assert.Check(t, errdefs.IsNotFound(err)) + assert.Check(t, is.ErrorContains(err, secretID)) - err = c.SecretRemove(ctx, "non-existin") - assert.Check(t, is.ErrorContains(err, "No such secret: non-existin")) + err = c.SecretRemove(ctx, "non-existing") + assert.Check(t, errdefs.IsNotFound(err)) + assert.Check(t, is.ErrorContains(err, "non-existing")) testName = "test_secret_with_labels_" + t.Name() secretID = createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), map[string]string{ @@ -214,6 +218,7 @@ func TestSecretsUpdate(t *testing.T) { // this test will produce an error in func UpdateSecret insp.Spec.Data = []byte("TESTINGDATA2") err = c.SecretUpdate(ctx, secretID, insp.Version, insp.Spec) + assert.Check(t, errdefs.IsInvalidParameter(err)) assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed")) } From 26f2eddaa3105a32b3c1747d839d5583ecef84f9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 15:57:24 +0200 Subject: [PATCH 10/13] integration/config: combine TestConfigCreateWithLabels with TestConfigsCreateAndDelete Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 42 ++++++++++--------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 1c4580ee5b..3bf46bc248 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -140,21 +140,31 @@ func TestConfigsCreateAndDelete(t *testing.T) { ctx := context.Background() testName := "test_config-" + t.Name() - - // This test case is ported from the original TestConfigsCreate configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) insp, _, err := c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Name, testName)) - // This test case is ported from the original TestConfigsDelete err = c.ConfigRemove(ctx, configID) assert.NilError(t, err) _, _, err = c.ConfigInspectWithRaw(ctx, configID) assert.Check(t, errdefs.IsNotFound(err)) assert.Check(t, is.ErrorContains(err, configID)) + + testName = "test_secret_with_labels_" + t.Name() + configID = createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), map[string]string{ + "key1": "value1", + "key2": "value2", + }) + + insp, _, err = c.ConfigInspectWithRaw(ctx, configID) + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Name, testName)) + assert.Check(t, is.Equal(len(insp.Spec.Labels), 2)) + assert.Check(t, is.Equal(insp.Spec.Labels["key1"], "value1")) + assert.Check(t, is.Equal(insp.Spec.Labels["key2"], "value2")) } func TestConfigsUpdate(t *testing.T) { @@ -318,32 +328,6 @@ func TestTemplatedConfig(t *testing.T) { assertAttachedStream(t, attach, "tmpfs on /templated_config type tmpfs") } -func TestConfigCreateWithLabels(t *testing.T) { - skip.If(t, testEnv.DaemonInfo.OSType != "linux") - - defer setupTest(t)() - d := swarm.NewSwarm(t, testEnv) - defer d.Stop(t) - c := d.NewClientT(t) - defer c.Close() - - ctx := context.Background() - - labels := map[string]string{ - "key1": "value1", - "key2": "value2", - } - testName := t.Name() - configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), labels) - - insp, _, err := c.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") From 632cc7019a1c532e3ec9d8594b14b44e7a260bc9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 16:01:28 +0200 Subject: [PATCH 11/13] integration/config: remove check that was already done in TestConfigInspect Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 3bf46bc248..ae082fded8 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -142,11 +142,7 @@ func TestConfigsCreateAndDelete(t *testing.T) { testName := "test_config-" + t.Name() configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil) - insp, _, err := c.ConfigInspectWithRaw(ctx, configID) - assert.NilError(t, err) - assert.Check(t, is.Equal(insp.Spec.Name, testName)) - - err = c.ConfigRemove(ctx, configID) + err := c.ConfigRemove(ctx, configID) assert.NilError(t, err) _, _, err = c.ConfigInspectWithRaw(ctx, configID) @@ -159,7 +155,7 @@ func TestConfigsCreateAndDelete(t *testing.T) { "key2": "value2", }) - insp, _, err = c.ConfigInspectWithRaw(ctx, configID) + insp, _, err := c.ConfigInspectWithRaw(ctx, configID) assert.NilError(t, err) assert.Check(t, is.Equal(insp.Spec.Name, testName)) assert.Check(t, is.Equal(len(insp.Spec.Labels), 2)) From 1a7ffe4fe45642c7482e206e15ae50eeba85e02a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 16:04:56 +0200 Subject: [PATCH 12/13] integration/secret: add check for empty list not producing an error Signed-off-by: Sebastiaan van Stijn --- integration/secret/secret_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 564b9c28fd..fb307bb60e 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -55,6 +55,10 @@ func TestSecretList(t *testing.T) { defer c.Close() ctx := context.Background() + configs, err := c.SecretList(ctx, types.SecretListOptions{}) + assert.NilError(t, err) + assert.Check(t, is.Equal(len(configs), 0)) + testName0 := "test0_" + t.Name() testName1 := "test1_" + t.Name() testNames := []string{testName0, testName1} From cdc39fa29c710c7b56aef827166f9e98bb7c20b8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Aug 2019 16:07:34 +0200 Subject: [PATCH 13/13] integration/config: add check for removing non-existing config Signed-off-by: Sebastiaan van Stijn --- integration/config/config_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index ae082fded8..7f56fab112 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -149,6 +149,10 @@ func TestConfigsCreateAndDelete(t *testing.T) { assert.Check(t, errdefs.IsNotFound(err)) assert.Check(t, is.ErrorContains(err, configID)) + err = c.ConfigRemove(ctx, "non-existing") + assert.Check(t, errdefs.IsNotFound(err)) + assert.Check(t, is.ErrorContains(err, "non-existing")) + testName = "test_secret_with_labels_" + t.Name() configID = createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), map[string]string{ "key1": "value1",