Browse Source

integration: sync minor changes between config and secret tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 5 năm trước cách đây
mục cha
commit
348f412d85

+ 14 - 18
integration/config/config_test.go

@@ -55,7 +55,6 @@ func TestConfigList(t *testing.T) {
 	defer d.Stop(t)
 	defer d.Stop(t)
 	c := d.NewClientT(t)
 	c := d.NewClientT(t)
 	defer c.Close()
 	defer c.Close()
-
 	ctx := context.Background()
 	ctx := context.Background()
 
 
 	// This test case is ported from the original TestConfigsEmptyList
 	// This test case is ported from the original TestConfigsEmptyList
@@ -137,7 +136,6 @@ func TestConfigsCreateAndDelete(t *testing.T) {
 	defer d.Stop(t)
 	defer d.Stop(t)
 	c := d.NewClientT(t)
 	c := d.NewClientT(t)
 	defer c.Close()
 	defer c.Close()
-
 	ctx := context.Background()
 	ctx := context.Background()
 
 
 	testName := "test_config-" + t.Name()
 	testName := "test_config-" + t.Name()
@@ -165,12 +163,9 @@ func TestConfigsUpdate(t *testing.T) {
 	defer d.Stop(t)
 	defer d.Stop(t)
 	c := d.NewClientT(t)
 	c := d.NewClientT(t)
 	defer c.Close()
 	defer c.Close()
-
 	ctx := context.Background()
 	ctx := context.Background()
 
 
 	testName := "test_config-" + t.Name()
 	testName := "test_config-" + t.Name()
-
-	// This test case is ported from the original TestConfigsCreate
 	configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil)
 	configID := createConfig(ctx, t, c, testName, []byte("TESTINGDATA"), nil)
 
 
 	insp, _, err := c.ConfigInspectWithRaw(ctx, configID)
 	insp, _, err := c.ConfigInspectWithRaw(ctx, configID)
@@ -255,11 +250,12 @@ func TestTemplatedConfig(t *testing.T) {
 	templatedConfig, err := c.ConfigCreate(ctx, configSpec)
 	templatedConfig, err := c.ConfigCreate(ctx, configSpec)
 	assert.Check(t, err)
 	assert.Check(t, err)
 
 
+	serviceName := "svc_" + t.Name()
 	serviceID := swarm.CreateService(t, d,
 	serviceID := swarm.CreateService(t, d,
 		swarm.ServiceWithConfig(
 		swarm.ServiceWithConfig(
 			&swarmtypes.ConfigReference{
 			&swarmtypes.ConfigReference{
 				File: &swarmtypes.ConfigReferenceFileTarget{
 				File: &swarmtypes.ConfigReferenceFileTarget{
-					Name: "/" + templatedConfigName,
+					Name: "templated_config",
 					UID:  "0",
 					UID:  "0",
 					GID:  "0",
 					GID:  "0",
 					Mode: 0600,
 					Mode: 0600,
@@ -292,7 +288,7 @@ func TestTemplatedConfig(t *testing.T) {
 				SecretName: referencedSecretName,
 				SecretName: referencedSecretName,
 			},
 			},
 		),
 		),
-		swarm.ServiceWithName("svc"),
+		swarm.ServiceWithName(serviceName),
 	)
 	)
 
 
 	poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, 1), swarm.ServicePoll, poll.WithTimeout(1*time.Minute))
 	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)
 	assert.Assert(t, len(tasks) > 0, "no running tasks found for service %s", serviceID)
 
 
 	attach := swarm.ExecTask(t, d, tasks[0], types.ExecConfig{
 	attach := swarm.ExecTask(t, d, tasks[0], types.ExecConfig{
-		Cmd:          []string{"/bin/cat", "/" + templatedConfigName},
+		Cmd:          []string{"/bin/cat", "/templated_config"},
 		AttachStdout: true,
 		AttachStdout: true,
 		AttachStderr: true,
 		AttachStderr: true,
 	})
 	})
 
 
-	expect := "SERVICE_NAME=svc\n" +
+	expect := "SERVICE_NAME=" + serviceName + "\n" +
 		"this is a secret\n" +
 		"this is a secret\n" +
 		"this is a config\n"
 		"this is a config\n"
 	assertAttachedStream(t, attach, expect)
 	assertAttachedStream(t, attach, expect)
@@ -316,14 +312,7 @@ func TestTemplatedConfig(t *testing.T) {
 		AttachStdout: true,
 		AttachStdout: true,
 		AttachStderr: 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) {
 func TestConfigCreateWithLabels(t *testing.T) {
@@ -365,8 +354,8 @@ func TestConfigCreateResolve(t *testing.T) {
 	ctx := context.Background()
 	ctx := context.Background()
 
 
 	configName := "test_config_" + t.Name()
 	configName := "test_config_" + t.Name()
-
 	configID := createConfig(ctx, t, c, configName, []byte("foo"), nil)
 	configID := createConfig(ctx, t, c, configName, []byte("foo"), nil)
+
 	fakeName := configID
 	fakeName := configID
 	fakeID := createConfig(ctx, t, c, fakeName, []byte("fake foo"), nil)
 	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")
 	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 {
 func configNamesFromList(entries []swarmtypes.Config) []string {
 	var values []string
 	var values []string
 	for _, entry := range entries {
 	for _, entry := range entries {

+ 0 - 2
integration/secret/secret_test.go

@@ -143,7 +143,6 @@ func TestSecretsCreateAndDelete(t *testing.T) {
 	})
 	})
 	assert.Check(t, is.ErrorContains(err, "already exists"))
 	assert.Check(t, is.ErrorContains(err, "already exists"))
 
 
-	// Ported from original TestSecretsDelete
 	err = c.SecretRemove(ctx, secretID)
 	err = c.SecretRemove(ctx, secretID)
 	assert.NilError(t, err)
 	assert.NilError(t, err)
 
 
@@ -153,7 +152,6 @@ func TestSecretsCreateAndDelete(t *testing.T) {
 	err = c.SecretRemove(ctx, "non-existin")
 	err = c.SecretRemove(ctx, "non-existin")
 	assert.Check(t, is.ErrorContains(err, "No such secret: non-existin"))
 	assert.Check(t, is.ErrorContains(err, "No such secret: non-existin"))
 
 
-	// Ported from original TestSecretsCreteaWithLabels
 	testName = "test_secret_with_labels_" + t.Name()
 	testName = "test_secret_with_labels_" + t.Name()
 	secretID = createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), map[string]string{
 	secretID = createSecret(ctx, t, c, testName, []byte("TESTINGDATA"), map[string]string{
 		"key1": "value1",
 		"key1": "value1",