Merge pull request #36430 from yongtang/02262018-config-test

Migrate config inspect test to api test
This commit is contained in:
Sebastiaan van Stijn 2018-02-28 11:50:52 +01:00 committed by GitHub
commit 973cf656dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 68 deletions

View file

@ -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)
}

View file

@ -2,6 +2,7 @@ package config
import (
"bytes"
"encoding/json"
"sort"
"testing"
"time"
@ -327,3 +328,27 @@ func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool)
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)
}