mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
secrets: add secret create and delete integration tests
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
dce2afbd81
commit
e63dc5cde4
2 changed files with 65 additions and 0 deletions
|
@ -284,6 +284,17 @@ func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
|
|||
return services
|
||||
}
|
||||
|
||||
func (d *SwarmDaemon) createSecret(c *check.C, secretSpec swarm.SecretSpec) string {
|
||||
status, out, err := d.SockRequest("POST", "/secrets", secretSpec)
|
||||
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
|
||||
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf("output: %q", string(out)))
|
||||
|
||||
var scr types.SecretCreateResponse
|
||||
c.Assert(json.Unmarshal(out, &scr), checker.IsNil)
|
||||
return scr.ID
|
||||
}
|
||||
|
||||
func (d *SwarmDaemon) listSecrets(c *check.C) []swarm.Secret {
|
||||
status, out, err := d.SockRequest("GET", "/secrets", nil)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
|
||||
|
@ -294,6 +305,21 @@ func (d *SwarmDaemon) listSecrets(c *check.C) []swarm.Secret {
|
|||
return secrets
|
||||
}
|
||||
|
||||
func (d *SwarmDaemon) getSecret(c *check.C, id string) *swarm.Secret {
|
||||
var secret swarm.Secret
|
||||
status, out, err := d.SockRequest("GET", "/secrets/"+id, nil)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
|
||||
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
||||
c.Assert(json.Unmarshal(out, &secret), checker.IsNil)
|
||||
return &secret
|
||||
}
|
||||
|
||||
func (d *SwarmDaemon) deleteSecret(c *check.C, id string) {
|
||||
status, out, err := d.SockRequest("DELETE", "/secrets/"+id, nil)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
|
||||
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
||||
}
|
||||
|
||||
func (d *SwarmDaemon) getSwarm(c *check.C) swarm.Swarm {
|
||||
var sw swarm.Swarm
|
||||
status, out, err := d.SockRequest("GET", "/swarm", nil)
|
||||
|
|
|
@ -1271,3 +1271,42 @@ func (s *DockerSwarmSuite) TestAPISwarmSecretsEmptyList(c *check.C) {
|
|||
c.Assert(secrets, checker.NotNil)
|
||||
c.Assert(len(secrets), checker.Equals, 0, check.Commentf("secrets: %#v", secrets))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmSecretsCreate(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
testName := "test_secret"
|
||||
id := d.createSecret(c, swarm.SecretSpec{
|
||||
swarm.Annotations{
|
||||
Name: testName,
|
||||
},
|
||||
[]byte("TESTINGDATA"),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
||||
|
||||
secrets := d.listSecrets(c)
|
||||
c.Assert(len(secrets), checker.Equals, 1, check.Commentf("secrets: %#v", secrets))
|
||||
name := secrets[0].Spec.Annotations.Name
|
||||
c.Assert(name, checker.Equals, testName, check.Commentf("secret: %s", name))
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestAPISwarmSecretsDelete(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
testName := "test_secret"
|
||||
id := d.createSecret(c, swarm.SecretSpec{
|
||||
swarm.Annotations{
|
||||
Name: testName,
|
||||
},
|
||||
[]byte("TESTINGDATA"),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
||||
|
||||
secret := d.getSecret(c, id)
|
||||
c.Assert(secret.ID, checker.Equals, id, check.Commentf("secret: %v", secret))
|
||||
|
||||
d.deleteSecret(c, secret.ID)
|
||||
status, out, err := d.SockRequest("GET", "/secrets/"+id, nil)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNotFound, check.Commentf("secret delete: %s", string(out)))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue