forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateSecretCmdExecIT.java
More file actions
52 lines (40 loc) · 1.91 KB
/
Copy pathCreateSecretCmdExecIT.java
File metadata and controls
52 lines (40 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.github.dockerjava.cmd.swarm;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.CreateSecretResponse;
import com.github.dockerjava.api.model.Secret;
import com.github.dockerjava.api.model.SecretSpec;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.collection.IsCollectionWithSize;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
public class CreateSecretCmdExecIT extends SwarmCmdIT {
public static final Logger LOG = LoggerFactory.getLogger(CreateSecretCmdExecIT.class);
@Test
public void testCreateSecret() throws Exception {
DockerClient dockerClient = startSwarm();
int length = 10;
boolean useLetters = true;
boolean useNumbers = false;
String secretName = RandomStringUtils.random(length, useLetters, useNumbers);
CreateSecretResponse exec = dockerClient.createSecretCmd(new SecretSpec().withName(secretName).withData("mon secret en clair")).exec();
assertThat(exec, notNullValue());
assertThat(exec.getId(), notNullValue());
LOG.info("Secret created with ID {}", exec.getId());
List<Secret> secrets = dockerClient.listSecretsCmd()
.withNameFilter(Lists.newArrayList(secretName))
.exec();
assertThat(secrets, IsCollectionWithSize.hasSize(1));
dockerClient.removeSecretCmd(secrets.get(0).getId())
.exec();
LOG.info("Secret removed with ID {}", exec.getId());
List<Secret> secretsAfterRemoved = dockerClient.listSecretsCmd()
.withNameFilter(Lists.newArrayList(secretName))
.exec();
assertThat(secretsAfterRemoved, IsCollectionWithSize.hasSize(0));
}
}