|
31 | 31 | import static org.hamcrest.Matchers.notNullValue;
|
32 | 32 | import static org.hamcrest.Matchers.nullValue;
|
33 | 33 | import static org.junit.Assert.assertThat;
|
| 34 | +import static org.mockito.Matchers.isNull; |
34 | 35 | import static org.mockito.Mockito.mock;
|
35 | 36 | import static org.mockito.Mockito.when;
|
36 | 37 |
|
|
56 | 57 | import com.spotify.docker.client.messages.RegistryConfigs;
|
57 | 58 | import com.spotify.docker.client.messages.ServiceCreateResponse;
|
58 | 59 | import com.spotify.docker.client.messages.swarm.Config;
|
| 60 | +import com.spotify.docker.client.messages.swarm.ConfigBind; |
59 | 61 | import com.spotify.docker.client.messages.swarm.ConfigCreateResponse;
|
| 62 | +import com.spotify.docker.client.messages.swarm.ConfigFile; |
60 | 63 | import com.spotify.docker.client.messages.swarm.ConfigSpec;
|
61 | 64 | import com.spotify.docker.client.messages.swarm.ContainerSpec;
|
62 | 65 | import com.spotify.docker.client.messages.swarm.EngineConfig;
|
63 | 66 | import com.spotify.docker.client.messages.swarm.Node;
|
64 | 67 | import com.spotify.docker.client.messages.swarm.NodeDescription;
|
65 | 68 | import com.spotify.docker.client.messages.swarm.NodeInfo;
|
66 | 69 | import com.spotify.docker.client.messages.swarm.NodeSpec;
|
| 70 | +import com.spotify.docker.client.messages.swarm.SecretSpec; |
67 | 71 | import com.spotify.docker.client.messages.swarm.ServiceSpec;
|
68 | 72 | import com.spotify.docker.client.messages.swarm.SwarmJoin;
|
69 | 73 | import com.spotify.docker.client.messages.swarm.TaskSpec;
|
@@ -617,6 +621,53 @@ private void enqueueServerApiEmptyResponse(final int statusCode) {
|
617 | 621 | );
|
618 | 622 | }
|
619 | 623 |
|
| 624 | + @Test |
| 625 | + public void testCreateServiceWithConfig() throws Exception { |
| 626 | + final DefaultDockerClient dockerClient = new DefaultDockerClient(builder); |
| 627 | + |
| 628 | + // build() calls /version to check what format of header to send |
| 629 | + enqueueServerApiVersion("1.30"); |
| 630 | + enqueueServerApiResponse(201, "fixtures/1.30/configCreateResponse.json"); |
| 631 | + |
| 632 | + final ConfigSpec configSpec = ConfigSpec |
| 633 | + .builder() |
| 634 | + .data(Base64.encodeAsString("foobar")) |
| 635 | + .name("foo.yaml") |
| 636 | + .build(); |
| 637 | + |
| 638 | + final ConfigCreateResponse configCreateResponse = dockerClient.createConfig(configSpec); |
| 639 | + assertThat(configCreateResponse.id(), equalTo("ktnbjxoalbkvbvedmg1urrz8h")); |
| 640 | + |
| 641 | + final ConfigBind configBind = ConfigBind.builder() |
| 642 | + .configName(configSpec.name()) |
| 643 | + .configId(configCreateResponse.id()) |
| 644 | + .file(ConfigFile.builder() |
| 645 | + .gid("1000") |
| 646 | + .uid("1000") |
| 647 | + .mode(600L) |
| 648 | + .name(configSpec.name()) |
| 649 | + .build() |
| 650 | + ).build(); |
| 651 | + |
| 652 | + final TaskSpec taskSpec = TaskSpec.builder() |
| 653 | + .containerSpec(ContainerSpec.builder() |
| 654 | + .image("this_image_is_found_in_the_registry") |
| 655 | + .configs(ImmutableList.of(configBind)) |
| 656 | + .build()) |
| 657 | + .build(); |
| 658 | + |
| 659 | + final ServiceSpec spec = ServiceSpec.builder() |
| 660 | + .name("test") |
| 661 | + .taskTemplate(taskSpec) |
| 662 | + .build(); |
| 663 | + |
| 664 | + enqueueServerApiVersion("1.30"); |
| 665 | + enqueueServerApiResponse(201, "fixtures/1.30/createServiceResponse.json"); |
| 666 | + |
| 667 | + final ServiceCreateResponse response = dockerClient.createService(spec); |
| 668 | + assertThat(response.id(), equalTo("ak7w3gjqoa3kuz8xcpnyy0pvl")); |
| 669 | + } |
| 670 | + |
620 | 671 | @Test
|
621 | 672 | public void testListConfigs() throws Exception {
|
622 | 673 | final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
|
|
0 commit comments