This fix migrates config inspect test in integration-cli
to api test.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,68 +0,0 @@ |
| 1 |
-// +build !windows |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "encoding/json" |
|
| 7 |
- |
|
| 8 |
- "github.com/docker/docker/api/types/swarm" |
|
| 9 |
- "github.com/docker/docker/integration-cli/checker" |
|
| 10 |
- "github.com/go-check/check" |
|
| 11 |
-) |
|
| 12 |
- |
|
| 13 |
-func (s *DockerSwarmSuite) TestConfigInspect(c *check.C) {
|
|
| 14 |
- d := s.AddDaemon(c, true, true) |
|
| 15 |
- |
|
| 16 |
- testName := "test_config" |
|
| 17 |
- id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
| 18 |
- Annotations: swarm.Annotations{
|
|
| 19 |
- Name: testName, |
|
| 20 |
- }, |
|
| 21 |
- Data: []byte("TESTINGDATA"),
|
|
| 22 |
- }) |
|
| 23 |
- c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
| 24 |
- |
|
| 25 |
- config := d.GetConfig(c, id) |
|
| 26 |
- c.Assert(config.Spec.Name, checker.Equals, testName) |
|
| 27 |
- |
|
| 28 |
- out, err := d.Cmd("config", "inspect", testName)
|
|
| 29 |
- c.Assert(err, checker.IsNil, check.Commentf(out)) |
|
| 30 |
- |
|
| 31 |
- var configs []swarm.Config |
|
| 32 |
- c.Assert(json.Unmarshal([]byte(out), &configs), checker.IsNil) |
|
| 33 |
- c.Assert(configs, checker.HasLen, 1) |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-func (s *DockerSwarmSuite) TestConfigInspectMultiple(c *check.C) {
|
|
| 37 |
- d := s.AddDaemon(c, true, true) |
|
| 38 |
- |
|
| 39 |
- testNames := []string{
|
|
| 40 |
- "test0", |
|
| 41 |
- "test1", |
|
| 42 |
- } |
|
| 43 |
- for _, n := range testNames {
|
|
| 44 |
- id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
| 45 |
- Annotations: swarm.Annotations{
|
|
| 46 |
- Name: n, |
|
| 47 |
- }, |
|
| 48 |
- Data: []byte("TESTINGDATA"),
|
|
| 49 |
- }) |
|
| 50 |
- c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
|
|
| 51 |
- |
|
| 52 |
- config := d.GetConfig(c, id) |
|
| 53 |
- c.Assert(config.Spec.Name, checker.Equals, n) |
|
| 54 |
- |
|
| 55 |
- } |
|
| 56 |
- |
|
| 57 |
- args := []string{
|
|
| 58 |
- "config", |
|
| 59 |
- "inspect", |
|
| 60 |
- } |
|
| 61 |
- args = append(args, testNames...) |
|
| 62 |
- out, err := d.Cmd(args...) |
|
| 63 |
- c.Assert(err, checker.IsNil, check.Commentf(out)) |
|
| 64 |
- |
|
| 65 |
- var configs []swarm.Config |
|
| 66 |
- c.Assert(json.Unmarshal([]byte(out), &configs), checker.IsNil) |
|
| 67 |
- c.Assert(configs, checker.HasLen, 2) |
|
| 68 |
-} |
| ... | ... |
@@ -2,6 +2,7 @@ package config |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
+ "encoding/json" |
|
| 5 | 6 |
"sort" |
| 6 | 7 |
"testing" |
| 7 | 8 |
"time" |
| ... | ... |
@@ -327,3 +328,27 @@ func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool) |
| 327 | 327 |
time.Sleep(100 * time.Millisecond) |
| 328 | 328 |
} |
| 329 | 329 |
} |
| 330 |
+ |
|
| 331 |
+func TestConfigInspect(t *testing.T) {
|
|
| 332 |
+ skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
|
| 333 |
+ |
|
| 334 |
+ defer setupTest(t)() |
|
| 335 |
+ d := swarm.NewSwarm(t, testEnv) |
|
| 336 |
+ defer d.Stop(t) |
|
| 337 |
+ client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) |
|
| 338 |
+ require.NoError(t, err) |
|
| 339 |
+ |
|
| 340 |
+ ctx := context.Background() |
|
| 341 |
+ |
|
| 342 |
+ testName := t.Name() |
|
| 343 |
+ configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
|
| 344 |
+ |
|
| 345 |
+ insp, body, err := client.ConfigInspectWithRaw(ctx, configID) |
|
| 346 |
+ require.NoError(t, err) |
|
| 347 |
+ assert.Equal(t, insp.Spec.Name, testName) |
|
| 348 |
+ |
|
| 349 |
+ var config swarmtypes.Config |
|
| 350 |
+ err = json.Unmarshal(body, &config) |
|
| 351 |
+ require.NoError(t, err) |
|
| 352 |
+ assert.Equal(t, config, insp) |
|
| 353 |
+} |