Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
| ... | ... |
@@ -284,6 +284,17 @@ func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
|
| 284 | 284 |
return services |
| 285 | 285 |
} |
| 286 | 286 |
|
| 287 |
+func (d *SwarmDaemon) createSecret(c *check.C, secretSpec swarm.SecretSpec) string {
|
|
| 288 |
+ status, out, err := d.SockRequest("POST", "/secrets", secretSpec)
|
|
| 289 |
+ |
|
| 290 |
+ c.Assert(err, checker.IsNil, check.Commentf(string(out))) |
|
| 291 |
+ c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf("output: %q", string(out)))
|
|
| 292 |
+ |
|
| 293 |
+ var scr types.SecretCreateResponse |
|
| 294 |
+ c.Assert(json.Unmarshal(out, &scr), checker.IsNil) |
|
| 295 |
+ return scr.ID |
|
| 296 |
+} |
|
| 297 |
+ |
|
| 287 | 298 |
func (d *SwarmDaemon) listSecrets(c *check.C) []swarm.Secret {
|
| 288 | 299 |
status, out, err := d.SockRequest("GET", "/secrets", nil)
|
| 289 | 300 |
c.Assert(err, checker.IsNil, check.Commentf(string(out))) |
| ... | ... |
@@ -294,6 +305,21 @@ func (d *SwarmDaemon) listSecrets(c *check.C) []swarm.Secret {
|
| 294 | 294 |
return secrets |
| 295 | 295 |
} |
| 296 | 296 |
|
| 297 |
+func (d *SwarmDaemon) getSecret(c *check.C, id string) *swarm.Secret {
|
|
| 298 |
+ var secret swarm.Secret |
|
| 299 |
+ status, out, err := d.SockRequest("GET", "/secrets/"+id, nil)
|
|
| 300 |
+ c.Assert(err, checker.IsNil, check.Commentf(string(out))) |
|
| 301 |
+ c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
|
| 302 |
+ c.Assert(json.Unmarshal(out, &secret), checker.IsNil) |
|
| 303 |
+ return &secret |
|
| 304 |
+} |
|
| 305 |
+ |
|
| 306 |
+func (d *SwarmDaemon) deleteSecret(c *check.C, id string) {
|
|
| 307 |
+ status, out, err := d.SockRequest("DELETE", "/secrets/"+id, nil)
|
|
| 308 |
+ c.Assert(err, checker.IsNil, check.Commentf(string(out))) |
|
| 309 |
+ c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
|
| 310 |
+} |
|
| 311 |
+ |
|
| 297 | 312 |
func (d *SwarmDaemon) getSwarm(c *check.C) swarm.Swarm {
|
| 298 | 313 |
var sw swarm.Swarm |
| 299 | 314 |
status, out, err := d.SockRequest("GET", "/swarm", nil)
|
| ... | ... |
@@ -1271,3 +1271,42 @@ func (s *DockerSwarmSuite) TestAPISwarmSecretsEmptyList(c *check.C) {
|
| 1271 | 1271 |
c.Assert(secrets, checker.NotNil) |
| 1272 | 1272 |
c.Assert(len(secrets), checker.Equals, 0, check.Commentf("secrets: %#v", secrets))
|
| 1273 | 1273 |
} |
| 1274 |
+ |
|
| 1275 |
+func (s *DockerSwarmSuite) TestAPISwarmSecretsCreate(c *check.C) {
|
|
| 1276 |
+ d := s.AddDaemon(c, true, true) |
|
| 1277 |
+ |
|
| 1278 |
+ testName := "test_secret" |
|
| 1279 |
+ id := d.createSecret(c, swarm.SecretSpec{
|
|
| 1280 |
+ swarm.Annotations{
|
|
| 1281 |
+ Name: testName, |
|
| 1282 |
+ }, |
|
| 1283 |
+ []byte("TESTINGDATA"),
|
|
| 1284 |
+ }) |
|
| 1285 |
+ c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
| 1286 |
+ |
|
| 1287 |
+ secrets := d.listSecrets(c) |
|
| 1288 |
+ c.Assert(len(secrets), checker.Equals, 1, check.Commentf("secrets: %#v", secrets))
|
|
| 1289 |
+ name := secrets[0].Spec.Annotations.Name |
|
| 1290 |
+ c.Assert(name, checker.Equals, testName, check.Commentf("secret: %s", name))
|
|
| 1291 |
+} |
|
| 1292 |
+ |
|
| 1293 |
+func (s *DockerSwarmSuite) TestAPISwarmSecretsDelete(c *check.C) {
|
|
| 1294 |
+ d := s.AddDaemon(c, true, true) |
|
| 1295 |
+ |
|
| 1296 |
+ testName := "test_secret" |
|
| 1297 |
+ id := d.createSecret(c, swarm.SecretSpec{
|
|
| 1298 |
+ swarm.Annotations{
|
|
| 1299 |
+ Name: testName, |
|
| 1300 |
+ }, |
|
| 1301 |
+ []byte("TESTINGDATA"),
|
|
| 1302 |
+ }) |
|
| 1303 |
+ c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
| 1304 |
+ |
|
| 1305 |
+ secret := d.getSecret(c, id) |
|
| 1306 |
+ c.Assert(secret.ID, checker.Equals, id, check.Commentf("secret: %v", secret))
|
|
| 1307 |
+ |
|
| 1308 |
+ d.deleteSecret(c, secret.ID) |
|
| 1309 |
+ status, out, err := d.SockRequest("GET", "/secrets/"+id, nil)
|
|
| 1310 |
+ c.Assert(err, checker.IsNil) |
|
| 1311 |
+ c.Assert(status, checker.Equals, http.StatusNotFound, check.Commentf("secret delete: %s", string(out)))
|
|
| 1312 |
+} |