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

Migrate TestSecretInspect from integration-cli to api tests

This fix migrates TestSecretInspect from integration-cli to api tests

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2018-02-02 22:23:12 +00:00
parent 3a6f8cfd51
commit 71c794d912
4 changed files with 113 additions and 23 deletions

View file

@ -10,29 +10,6 @@ import (
"github.com/go-check/check"
)
func (s *DockerSwarmSuite) TestSecretInspect(c *check.C) {
d := s.AddDaemon(c, true, true)
testName := "test_secret"
id := d.CreateSecret(c, swarm.SecretSpec{
Annotations: swarm.Annotations{
Name: testName,
},
Data: []byte("TESTINGDATA"),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
secret := d.GetSecret(c, id)
c.Assert(secret.Spec.Name, checker.Equals, testName)
out, err := d.Cmd("secret", "inspect", testName)
c.Assert(err, checker.IsNil, check.Commentf(out))
var secrets []swarm.Secret
c.Assert(json.Unmarshal([]byte(out), &secrets), checker.IsNil)
c.Assert(secrets, checker.HasLen, 1)
}
func (s *DockerSwarmSuite) TestSecretInspectMultiple(c *check.C) {
d := s.AddDaemon(c, true, true)

View file

@ -0,0 +1,35 @@
package secret
import (
"fmt"
"os"
"testing"
"github.com/docker/docker/internal/test/environment"
)
var testEnv *environment.Execution
const dockerdBinary = "dockerd"
func TestMain(m *testing.M) {
var err error
testEnv, err = environment.New()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = environment.EnsureFrozenImagesLinux(testEnv)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
testEnv.Print()
os.Exit(m.Run())
}
func setupTest(t *testing.T) func() {
environment.ProtectAll(t, testEnv)
return func() { testEnv.Clean(t) }
}

View file

@ -0,0 +1,43 @@
package secret
import (
"testing"
swarmtypes "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/integration/util/swarm"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func TestSecretInspect(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
defer setupTest(t)()
d := swarm.NewSwarm(t, testEnv)
defer d.Stop(t)
client, err := request.NewClientForHost(d.Sock())
require.NoError(t, err)
ctx := context.Background()
testName := "test_secret"
secretResp, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{
Annotations: swarmtypes.Annotations{
Name: testName,
},
Data: []byte("TESTINGDATA"),
})
require.NoError(t, err)
assert.NotEqual(t, secretResp.ID, "")
secret, _, err := client.SecretInspectWithRaw(context.Background(), secretResp.ID)
require.NoError(t, err)
assert.Equal(t, secret.Spec.Name, testName)
secret, _, err = client.SecretInspectWithRaw(context.Background(), testName)
require.NoError(t, err)
assert.Equal(t, secret.ID, secretResp.ID)
}

View file

@ -0,0 +1,35 @@
package swarm
import (
"fmt"
"testing"
swarmtypes "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/integration-cli/daemon"
"github.com/docker/docker/internal/test/environment"
"github.com/stretchr/testify/require"
)
const (
dockerdBinary = "dockerd"
defaultSwarmPort = 2477
)
func NewSwarm(t *testing.T, testEnv *environment.Execution) *daemon.Swarm {
d := &daemon.Swarm{
Daemon: daemon.New(t, "", dockerdBinary, daemon.Config{
Experimental: testEnv.DaemonInfo.ExperimentalBuild,
}),
// TODO: better method of finding an unused port
Port: defaultSwarmPort,
}
// TODO: move to a NewSwarm constructor
d.ListenAddr = fmt.Sprintf("0.0.0.0:%d", d.Port)
// avoid networking conflicts
args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
d.StartWithBusybox(t, args...)
require.NoError(t, d.Init(swarmtypes.InitRequest{}))
return d
}