|
| 1 | +/* |
| 2 | + * Copyright 2019 ThoughtWorks, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package cd.go.contrib.elasticagents.docker; |
| 18 | + |
| 19 | +import cd.go.contrib.elasticagents.docker.requests.CreateAgentRequest; |
| 20 | +import cd.go.contrib.elasticagents.docker.requests.JobCompletionRequest; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +import java.util.Collections; |
| 24 | +import java.util.Map; |
| 25 | + |
| 26 | +import static org.hamcrest.Matchers.is; |
| 27 | +import static org.junit.Assert.assertThat; |
| 28 | + |
| 29 | +public class ClusterProfilePropertiesTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + public void shouldGenerateSameUUIDForClusterProfileProperties() { |
| 33 | + Map<String, String> clusterProfileConfigurations = Collections.singletonMap("go_server_url", "http://go-server-url/go"); |
| 34 | + ClusterProfileProperties clusterProfileProperties = ClusterProfileProperties.fromConfiguration(clusterProfileConfigurations); |
| 35 | + |
| 36 | + assertThat(clusterProfileProperties.uuid(), is(clusterProfileProperties.uuid())); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void shouldGenerateSameUUIDForClusterProfilePropertiesAcrossRequests() { |
| 41 | + String createAgentRequestJSON = "{\n" + |
| 42 | + " \"auto_register_key\": \"secret-key\",\n" + |
| 43 | + " \"elastic_agent_profile_properties\": {\n" + |
| 44 | + " \"key1\": \"value1\",\n" + |
| 45 | + " \"key2\": \"value2\"\n" + |
| 46 | + " },\n" + |
| 47 | + " \"cluster_profile_properties\": {\n" + |
| 48 | + " \"go_server_url\": \"https://foo.com/go\",\n" + |
| 49 | + " \"docker_uri\": \"unix:///var/run/docker.sock\"\n" + |
| 50 | + " },\n" + |
| 51 | + " \"environment\": \"prod\"\n" + |
| 52 | + "}"; |
| 53 | + |
| 54 | + CreateAgentRequest createAgentRequest = CreateAgentRequest.fromJSON(createAgentRequestJSON); |
| 55 | + |
| 56 | + String jobCompletionRequestJSON = "{\n" + |
| 57 | + " \"elastic_agent_id\": \"ea1\",\n" + |
| 58 | + " \"elastic_agent_profile_properties\": {\n" + |
| 59 | + " \"Image\": \"alpine:latest\"\n" + |
| 60 | + " },\n" + |
| 61 | + " \"cluster_profile_properties\": {\n" + |
| 62 | + " \"go_server_url\": \"https://foo.com/go\", \n" + |
| 63 | + " \"docker_uri\": \"unix:///var/run/docker.sock\"\n" + |
| 64 | + " },\n" + |
| 65 | + " \"job_identifier\": {\n" + |
| 66 | + " \"pipeline_name\": \"test-pipeline\",\n" + |
| 67 | + " \"pipeline_counter\": 1,\n" + |
| 68 | + " \"pipeline_label\": \"Test Pipeline\",\n" + |
| 69 | + " \"stage_name\": \"test-stage\",\n" + |
| 70 | + " \"stage_counter\": \"1\",\n" + |
| 71 | + " \"job_name\": \"test-job\",\n" + |
| 72 | + " \"job_id\": 100\n" + |
| 73 | + " }\n" + |
| 74 | + "}"; |
| 75 | + |
| 76 | + JobCompletionRequest jobCompletionRequest = JobCompletionRequest.fromJSON(jobCompletionRequestJSON); |
| 77 | + assertThat(jobCompletionRequest.getClusterProfileProperties().uuid(), is(createAgentRequest.getClusterProfileProperties().uuid())); |
| 78 | + } |
| 79 | +} |
0 commit comments