Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e57cea

Browse files
committed
moved integration tests from docker_cli_config_create_test.go to integration/config
Signed-off-by: Arash Deshmeh <[email protected]>
1 parent 23f4a3d commit 0e57cea

2 files changed

Lines changed: 88 additions & 112 deletions

File tree

integration-cli/docker_cli_config_create_test.go

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -7,111 +7,10 @@ import (
77
"os"
88
"strings"
99

10-
"github.com/docker/docker/api/types/swarm"
1110
"github.com/docker/docker/integration-cli/checker"
1211
"github.com/go-check/check"
1312
)
1413

15-
func (s *DockerSwarmSuite) TestConfigCreate(c *check.C) {
16-
d := s.AddDaemon(c, true, true)
17-
18-
testName := "test_config"
19-
id := d.CreateConfig(c, swarm.ConfigSpec{
20-
Annotations: swarm.Annotations{
21-
Name: testName,
22-
},
23-
Data: []byte("TESTINGDATA"),
24-
})
25-
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
26-
27-
config := d.GetConfig(c, id)
28-
c.Assert(config.Spec.Name, checker.Equals, testName)
29-
}
30-
31-
func (s *DockerSwarmSuite) TestConfigCreateWithLabels(c *check.C) {
32-
d := s.AddDaemon(c, true, true)
33-
34-
testName := "test_config"
35-
id := d.CreateConfig(c, swarm.ConfigSpec{
36-
Annotations: swarm.Annotations{
37-
Name: testName,
38-
Labels: map[string]string{
39-
"key1": "value1",
40-
"key2": "value2",
41-
},
42-
},
43-
Data: []byte("TESTINGDATA"),
44-
})
45-
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
46-
47-
config := d.GetConfig(c, id)
48-
c.Assert(config.Spec.Name, checker.Equals, testName)
49-
c.Assert(len(config.Spec.Labels), checker.Equals, 2)
50-
c.Assert(config.Spec.Labels["key1"], checker.Equals, "value1")
51-
c.Assert(config.Spec.Labels["key2"], checker.Equals, "value2")
52-
}
53-
54-
// Test case for 28884
55-
func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) {
56-
d := s.AddDaemon(c, true, true)
57-
58-
name := "test_config"
59-
id := d.CreateConfig(c, swarm.ConfigSpec{
60-
Annotations: swarm.Annotations{
61-
Name: name,
62-
},
63-
Data: []byte("foo"),
64-
})
65-
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
66-
67-
fake := d.CreateConfig(c, swarm.ConfigSpec{
68-
Annotations: swarm.Annotations{
69-
Name: id,
70-
},
71-
Data: []byte("fake foo"),
72-
})
73-
c.Assert(fake, checker.Not(checker.Equals), "", check.Commentf("configs: %s", fake))
74-
75-
out, err := d.Cmd("config", "ls")
76-
c.Assert(err, checker.IsNil)
77-
c.Assert(out, checker.Contains, name)
78-
c.Assert(out, checker.Contains, fake)
79-
80-
out, err = d.Cmd("config", "rm", id)
81-
c.Assert(err, checker.IsNil)
82-
c.Assert(out, checker.Contains, id)
83-
84-
// Fake one will remain
85-
out, err = d.Cmd("config", "ls")
86-
c.Assert(err, checker.IsNil)
87-
c.Assert(out, checker.Not(checker.Contains), name)
88-
c.Assert(out, checker.Contains, fake)
89-
90-
// Remove based on name prefix of the fake one
91-
// (which is the same as the ID of foo one) should not work
92-
// as search is only done based on:
93-
// - Full ID
94-
// - Full Name
95-
// - Partial ID (prefix)
96-
out, err = d.Cmd("config", "rm", id[:5])
97-
c.Assert(err, checker.Not(checker.IsNil))
98-
c.Assert(out, checker.Not(checker.Contains), id)
99-
out, err = d.Cmd("config", "ls")
100-
c.Assert(err, checker.IsNil)
101-
c.Assert(out, checker.Not(checker.Contains), name)
102-
c.Assert(out, checker.Contains, fake)
103-
104-
// Remove based on ID prefix of the fake one should succeed
105-
out, err = d.Cmd("config", "rm", fake[:5])
106-
c.Assert(err, checker.IsNil)
107-
c.Assert(out, checker.Contains, fake[:5])
108-
out, err = d.Cmd("config", "ls")
109-
c.Assert(err, checker.IsNil)
110-
c.Assert(out, checker.Not(checker.Contains), name)
111-
c.Assert(out, checker.Not(checker.Contains), id)
112-
c.Assert(out, checker.Not(checker.Contains), fake)
113-
}
114-
11514
func (s *DockerSwarmSuite) TestConfigCreateWithFile(c *check.C) {
11615
d := s.AddDaemon(c, true, true)
11716

integration/config/config_test.go

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,10 @@ func TestConfigList(t *testing.T) {
4545

4646
config1ID := createConfig(ctx, t, client, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"})
4747

48-
names := func(entries []swarmtypes.Config) []string {
49-
var values []string
50-
for _, entry := range entries {
51-
values = append(values, entry.Spec.Name)
52-
}
53-
sort.Strings(values)
54-
return values
55-
}
56-
5748
// test by `config ls`
5849
entries, err := client.ConfigList(ctx, types.ConfigListOptions{})
5950
assert.NilError(t, err)
60-
assert.Check(t, is.DeepEqual(names(entries), testNames))
51+
assert.Check(t, is.DeepEqual(configNamesFromList(entries), testNames))
6152

6253
testCases := []struct {
6354
filters filters.Args
@@ -92,7 +83,7 @@ func TestConfigList(t *testing.T) {
9283
Filters: tc.filters,
9384
})
9485
assert.NilError(t, err)
95-
assert.Check(t, is.DeepEqual(names(entries), tc.expected))
86+
assert.Check(t, is.DeepEqual(configNamesFromList(entries), tc.expected))
9687

9788
}
9889
}
@@ -354,3 +345,89 @@ func TestConfigInspect(t *testing.T) {
354345
assert.NilError(t, err)
355346
assert.Check(t, is.DeepEqual(config, insp))
356347
}
348+
349+
func TestConfigCreateWithLabels(t *testing.T) {
350+
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
351+
352+
defer setupTest(t)()
353+
d := swarm.NewSwarm(t, testEnv)
354+
defer d.Stop(t)
355+
client := d.NewClientT(t)
356+
defer client.Close()
357+
358+
ctx := context.Background()
359+
360+
labels := map[string]string{
361+
"key1": "value1",
362+
"key2": "value2",
363+
}
364+
testName := t.Name()
365+
configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), labels)
366+
367+
insp, _, err := client.ConfigInspectWithRaw(ctx, configID)
368+
assert.NilError(t, err)
369+
assert.Check(t, is.Equal(insp.Spec.Name, testName))
370+
assert.Check(t, is.Equal(2, len(insp.Spec.Labels)))
371+
assert.Check(t, is.Equal("value1", insp.Spec.Labels["key1"]))
372+
assert.Check(t, is.Equal("value2", insp.Spec.Labels["key2"]))
373+
}
374+
375+
// Test case for 28884
376+
func TestConfigCreateResolve(t *testing.T) {
377+
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
378+
379+
defer setupTest(t)()
380+
d := swarm.NewSwarm(t, testEnv)
381+
defer d.Stop(t)
382+
client := d.NewClientT(t)
383+
defer client.Close()
384+
385+
ctx := context.Background()
386+
387+
configName := "test_config_" + t.Name()
388+
389+
configID := createConfig(ctx, t, client, configName, []byte("foo"), nil)
390+
fakeName := configID
391+
fakeID := createConfig(ctx, t, client, fakeName, []byte("fake foo"), nil)
392+
393+
entries, err := client.ConfigList(ctx, types.ConfigListOptions{})
394+
assert.NilError(t, err)
395+
assert.Assert(t, is.Contains(configNamesFromList(entries), configName))
396+
assert.Assert(t, is.Contains(configNamesFromList(entries), fakeName))
397+
398+
err = client.ConfigRemove(ctx, configID)
399+
assert.NilError(t, err)
400+
401+
// Fake one will remain
402+
entries, err = client.ConfigList(ctx, types.ConfigListOptions{})
403+
assert.NilError(t, err)
404+
assert.Assert(t, is.DeepEqual(configNamesFromList(entries), []string{fakeName}))
405+
406+
// Remove based on name prefix of the fake one
407+
// (which is the same as the ID of foo one) should not work
408+
// as search is only done based on:
409+
// - Full ID
410+
// - Full Name
411+
// - Partial ID (prefix)
412+
err = client.ConfigRemove(ctx, configID[:5])
413+
assert.Assert(t, nil != err)
414+
entries, err = client.ConfigList(ctx, types.ConfigListOptions{})
415+
assert.NilError(t, err)
416+
assert.Assert(t, is.DeepEqual(configNamesFromList(entries), []string{fakeName}))
417+
418+
// Remove based on ID prefix of the fake one should succeed
419+
err = client.ConfigRemove(ctx, fakeID[:5])
420+
assert.NilError(t, err)
421+
entries, err = client.ConfigList(ctx, types.ConfigListOptions{})
422+
assert.NilError(t, err)
423+
assert.Assert(t, is.Equal(0, len(entries)))
424+
}
425+
426+
func configNamesFromList(entries []swarmtypes.Config) []string {
427+
var values []string
428+
for _, entry := range entries {
429+
values = append(values, entry.Spec.Name)
430+
}
431+
sort.Strings(values)
432+
return values
433+
}

0 commit comments

Comments
 (0)