mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Migrate some config secret tests to api test
This fix migrates some secret create tests to api tests, and remove redundant TestConfigCreate. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
5a7bbd6dba
commit
99e2818850
2 changed files with 24 additions and 69 deletions
|
@ -12,45 +12,6 @@ import (
|
|||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestSecretCreate(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)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSecretCreateWithLabels(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
testName := "test_secret"
|
||||
id := d.CreateSecret(c, swarm.SecretSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
Name: testName,
|
||||
Labels: map[string]string{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
},
|
||||
},
|
||||
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)
|
||||
c.Assert(len(secret.Spec.Labels), checker.Equals, 2)
|
||||
c.Assert(secret.Spec.Labels["key1"], checker.Equals, "value1")
|
||||
c.Assert(secret.Spec.Labels["key2"], checker.Equals, "value2")
|
||||
}
|
||||
|
||||
// Test case for 28884
|
||||
func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
|
|
@ -129,32 +129,7 @@ func createSecret(ctx context.Context, t *testing.T, client client.APIClient, na
|
|||
return secret.ID
|
||||
}
|
||||
|
||||
func TestSecretsCreate(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 := "test_secret"
|
||||
createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
// create an already existin secret, daemon should return a status code of 409
|
||||
_, err = client.SecretCreate(ctx, swarmtypes.SecretSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: testName,
|
||||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
testutil.ErrorContains(t, err, "already exists")
|
||||
}
|
||||
|
||||
func TestSecretsDelete(t *testing.T) {
|
||||
func TestSecretsCreateAndDelete(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
||||
|
||||
defer setupTest(t)()
|
||||
|
@ -167,12 +142,17 @@ func TestSecretsDelete(t *testing.T) {
|
|||
|
||||
testName := "test_secret"
|
||||
secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
insp, _, err := client.SecretInspectWithRaw(ctx, secretID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, insp.ID, secretID)
|
||||
// create an already existin secret, daemon should return a status code of 409
|
||||
_, err = client.SecretCreate(ctx, swarmtypes.SecretSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: testName,
|
||||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
testutil.ErrorContains(t, err, "already exists")
|
||||
|
||||
// Ported from original TestSecretsDelete
|
||||
err = client.SecretRemove(ctx, secretID)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -181,6 +161,20 @@ func TestSecretsDelete(t *testing.T) {
|
|||
|
||||
err = client.SecretRemove(ctx, "non-existin")
|
||||
testutil.ErrorContains(t, err, "No such secret: non-existin")
|
||||
|
||||
// Ported from original TestSecretsCreteaWithLabels
|
||||
testName = "test_secret_with_labels"
|
||||
secretID = createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), map[string]string{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
})
|
||||
|
||||
insp, _, err := client.SecretInspectWithRaw(ctx, secretID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, insp.Spec.Name, testName)
|
||||
assert.Equal(t, len(insp.Spec.Labels), 2)
|
||||
assert.Equal(t, insp.Spec.Labels["key1"], "value1")
|
||||
assert.Equal(t, insp.Spec.Labels["key2"], "value2")
|
||||
}
|
||||
|
||||
func TestSecretsUpdate(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue