|
16 | 16 |
|
17 | 17 | package org.hypertrace.agent.core;
|
18 | 18 |
|
| 19 | +import com.google.protobuf.util.JsonFormat; |
| 20 | +import java.io.File; |
| 21 | +import java.io.FileOutputStream; |
19 | 22 | import java.io.IOException;
|
20 | 23 | import java.net.URL;
|
21 | 24 | import java.util.Arrays;
|
22 | 25 | import org.hypertrace.agent.config.Config.AgentConfig;
|
23 | 26 | import org.hypertrace.agent.config.Config.PropagationFormat;
|
24 | 27 | import org.junit.jupiter.api.Assertions;
|
25 | 28 | import org.junit.jupiter.api.Test;
|
| 29 | +import org.junit.jupiter.api.io.TempDir; |
26 | 30 | import org.junitpioneer.jupiter.ClearSystemProperty;
|
27 | 31 |
|
28 | 32 | public class HypertraceConfigTest {
|
@@ -66,6 +70,25 @@ public void defaultValues() throws IOException {
|
66 | 70 | public void config() throws IOException {
|
67 | 71 | URL resource = getClass().getClassLoader().getResource("config.yaml");
|
68 | 72 | AgentConfig agentConfig = HypertraceConfig.load(resource.getPath());
|
| 73 | + assertConfig(agentConfig); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void jsonConfig(@TempDir File tempFolder) throws IOException { |
| 78 | + URL resource = getClass().getClassLoader().getResource("config.yaml"); |
| 79 | + AgentConfig agentConfig = HypertraceConfig.load(resource.getPath()); |
| 80 | + |
| 81 | + String jsonConfig = JsonFormat.printer().print(agentConfig); |
| 82 | + Assertions.assertTrue(!jsonConfig.contains("value")); |
| 83 | + File jsonFile = new File(tempFolder, "config.jSon"); |
| 84 | + FileOutputStream fileOutputStream = new FileOutputStream(jsonFile); |
| 85 | + fileOutputStream.write(jsonConfig.getBytes()); |
| 86 | + |
| 87 | + agentConfig = HypertraceConfig.load(jsonFile.getAbsolutePath()); |
| 88 | + assertConfig(agentConfig); |
| 89 | + } |
| 90 | + |
| 91 | + private void assertConfig(AgentConfig agentConfig) { |
69 | 92 | Assertions.assertEquals("service", agentConfig.getServiceName().getValue());
|
70 | 93 | Assertions.assertEquals(
|
71 | 94 | Arrays.asList(PropagationFormat.B3), agentConfig.getPropagationFormatsList());
|
|
0 commit comments