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",