1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

integration: sync minor changes between config and secret tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-08-19 15:23:49 +02:00
parent a45c89ecd1
commit 348f412d85
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 14 additions and 20 deletions

View file

@ -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 {

View file

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