浏览代码

Migrate config inspect test to api test

This fix migrates config inspect test in integration-cli
to api test.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Yong Tang 7 年之前
父节点
当前提交
4b99d78207
共有 2 个文件被更改,包括 25 次插入68 次删除
  1. 0 68
      integration-cli/docker_cli_config_inspect_test.go
  2. 25 0
      integration/config/config_test.go

+ 0 - 68
integration-cli/docker_cli_config_inspect_test.go

@@ -1,68 +0,0 @@
-// +build !windows
-
-package main
-
-import (
-	"encoding/json"
-
-	"github.com/docker/docker/api/types/swarm"
-	"github.com/docker/docker/integration-cli/checker"
-	"github.com/go-check/check"
-)
-
-func (s *DockerSwarmSuite) TestConfigInspect(c *check.C) {
-	d := s.AddDaemon(c, true, true)
-
-	testName := "test_config"
-	id := d.CreateConfig(c, swarm.ConfigSpec{
-		Annotations: swarm.Annotations{
-			Name: testName,
-		},
-		Data: []byte("TESTINGDATA"),
-	})
-	c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
-
-	config := d.GetConfig(c, id)
-	c.Assert(config.Spec.Name, checker.Equals, testName)
-
-	out, err := d.Cmd("config", "inspect", testName)
-	c.Assert(err, checker.IsNil, check.Commentf(out))
-
-	var configs []swarm.Config
-	c.Assert(json.Unmarshal([]byte(out), &configs), checker.IsNil)
-	c.Assert(configs, checker.HasLen, 1)
-}
-
-func (s *DockerSwarmSuite) TestConfigInspectMultiple(c *check.C) {
-	d := s.AddDaemon(c, true, true)
-
-	testNames := []string{
-		"test0",
-		"test1",
-	}
-	for _, n := range testNames {
-		id := d.CreateConfig(c, swarm.ConfigSpec{
-			Annotations: swarm.Annotations{
-				Name: n,
-			},
-			Data: []byte("TESTINGDATA"),
-		})
-		c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
-
-		config := d.GetConfig(c, id)
-		c.Assert(config.Spec.Name, checker.Equals, n)
-
-	}
-
-	args := []string{
-		"config",
-		"inspect",
-	}
-	args = append(args, testNames...)
-	out, err := d.Cmd(args...)
-	c.Assert(err, checker.IsNil, check.Commentf(out))
-
-	var configs []swarm.Config
-	c.Assert(json.Unmarshal([]byte(out), &configs), checker.IsNil)
-	c.Assert(configs, checker.HasLen, 2)
-}

+ 25 - 0
integration/config/config_test.go

@@ -2,6 +2,7 @@ package config
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"encoding/json"
 	"sort"
 	"sort"
 	"testing"
 	"testing"
 	"time"
 	"time"
@@ -327,3 +328,27 @@ func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool)
 		time.Sleep(100 * time.Millisecond)
 		time.Sleep(100 * time.Millisecond)
 	}
 	}
 }
 }
+
+func TestConfigInspect(t *testing.T) {
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
+
+	defer setupTest(t)()
+	d := swarm.NewSwarm(t, testEnv)
+	defer d.Stop(t)
+	client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
+	require.NoError(t, err)
+
+	ctx := context.Background()
+
+	testName := t.Name()
+	configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
+
+	insp, body, err := client.ConfigInspectWithRaw(ctx, configID)
+	require.NoError(t, err)
+	assert.Equal(t, insp.Spec.Name, testName)
+
+	var config swarmtypes.Config
+	err = json.Unmarshal(body, &config)
+	require.NoError(t, err)
+	assert.Equal(t, config, insp)
+}