Skip to content

Commit 646aeb1

Browse files
authored
Merge pull request #63 from cisco-open/fix/v0.9.0/add-cli-tests
Add tests for the CLI mode
2 parents e5fdb0c + 2f63377 commit 646aeb1

File tree

11 files changed

+145
-0
lines changed

11 files changed

+145
-0
lines changed

src/main/java/io/opentelemetry/contrib/generator/telemetry/cli/CLIProcessor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ private static PayloadHandler getPayloadHandler(String targetEnvYAML) {
118118
"must be provided in environment target YAML");
119119
}
120120
AuthHandler authHandler;
121+
if (targetEnvironmentDetails.getAuthMode() == null) {
122+
throw new GeneratorException("Missing authMode in environment target YAML");
123+
}
124+
if (!(targetEnvironmentDetails.getAuthMode().equalsIgnoreCase("NONE") ||
125+
targetEnvironmentDetails.getAuthMode().equalsIgnoreCase("BASIC"))) {
126+
throw new GeneratorException("Invalid authMode in environment target YAML. Allowed - NONE, BASIC");
127+
}
121128
if (targetEnvironmentDetails.getAuthMode().equalsIgnoreCase("NONE")) {
122129
authHandler = new NoAuthHandler();
123130
} else {

src/test/java/io/opentelemetry/contrib/generator/telemetry/TestCLIProcessor.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package io.opentelemetry.contrib.generator.telemetry;
1818

19+
import io.opentelemetry.contrib.generator.core.exception.GeneratorException;
1920
import io.opentelemetry.contrib.generator.telemetry.cli.CLIProcessor;
21+
import org.apache.commons.cli.MissingOptionException;
2022
import org.apache.commons.cli.ParseException;
2123
import org.testng.annotations.Test;
2224

@@ -50,4 +52,104 @@ public void testMetricsTracesBasicAuthGRPC() throws ParseException {
5052
CLIProcessor.main(cliArgs);
5153
}
5254

55+
@Test(expectedExceptions = MissingOptionException.class)
56+
public void testWithoutEntityDefinition() throws ParseException {
57+
String noAuthTargetYAML = Paths.get(cliResourcesPath, "target-noauth.yaml").toString();
58+
String[] cliArgs = new String[] { METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noAuthTargetYAML };
59+
CLIProcessor.main(cliArgs);
60+
}
61+
62+
@Test(expectedExceptions = GeneratorException.class)
63+
public void testWithOnlyEntityDefinition() throws ParseException {
64+
String noAuthTargetYAML = Paths.get(cliResourcesPath, "target-noauth.yaml").toString();
65+
String[] cliArgs = new String[] { "-e", ENTITIES_YAML, "-t", noAuthTargetYAML };
66+
CLIProcessor.main(cliArgs);
67+
}
68+
69+
@Test(expectedExceptions = MissingOptionException.class)
70+
public void testWithoutTargetAuthYAML() throws ParseException {
71+
String[] cliArgs = new String[] { "-e", ENTITIES_YAML, METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML };
72+
CLIProcessor.main(cliArgs);
73+
}
74+
75+
@Test(expectedExceptions = GeneratorException.class)
76+
public void testWithoutAuthMode() throws ParseException {
77+
String noAuthModeYAML = Paths.get(cliResourcesPath, "negative", "no-auth-mode.yaml").toString();
78+
String[] cliArgs = new String[] {
79+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noAuthModeYAML
80+
};
81+
CLIProcessor.main(cliArgs);
82+
}
83+
84+
@Test(expectedExceptions = GeneratorException.class)
85+
public void testWithInvalidAuthMode() throws ParseException {
86+
String invalidAuthModeYAML = Paths.get(cliResourcesPath, "negative", "invalid-auth-mode.yaml").toString();
87+
String[] cliArgs = new String[] {
88+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", invalidAuthModeYAML
89+
};
90+
CLIProcessor.main(cliArgs);
91+
}
92+
93+
@Test(expectedExceptions = GeneratorException.class)
94+
public void testWithoutEndpoint() throws ParseException {
95+
String noEndpointYAML = Paths.get(cliResourcesPath, "negative", "without-endpoint.yaml").toString();
96+
String[] cliArgs = new String[] {
97+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noEndpointYAML
98+
};
99+
CLIProcessor.main(cliArgs);
100+
}
101+
102+
@Test(expectedExceptions = GeneratorException.class)
103+
public void testWithOnlyGRPCHost() throws ParseException {
104+
String onlyGRPCHostYAML = Paths.get(cliResourcesPath, "negative", "only-grpc-host.yaml").toString();
105+
String[] cliArgs = new String[] {
106+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", onlyGRPCHostYAML
107+
};
108+
CLIProcessor.main(cliArgs);
109+
}
110+
111+
@Test(expectedExceptions = GeneratorException.class)
112+
public void testWithOnlyGRPCPort() throws ParseException {
113+
String onlyGRPCPortYAML = Paths.get(cliResourcesPath, "negative", "only-grpc-port.yaml").toString();
114+
String[] cliArgs = new String[] {
115+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", onlyGRPCPortYAML
116+
};
117+
CLIProcessor.main(cliArgs);
118+
}
119+
120+
@Test
121+
public void testWithAuthModeNoneAndBasicCredentials() throws ParseException {
122+
String noneAuthModeYAML = Paths.get(cliResourcesPath, "negative", "none-auth-mode.yaml").toString();
123+
String[] cliArgs = new String[] {
124+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noneAuthModeYAML
125+
};
126+
CLIProcessor.main(cliArgs);
127+
}
128+
129+
@Test(expectedExceptions = GeneratorException.class)
130+
public void testWithAuthModeBasicAndNoUsername() throws ParseException {
131+
String noUsernameYAML = Paths.get(cliResourcesPath, "negative", "no-username.yaml").toString();
132+
String[] cliArgs = new String[] {
133+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noUsernameYAML
134+
};
135+
CLIProcessor.main(cliArgs);
136+
}
137+
138+
@Test(expectedExceptions = GeneratorException.class)
139+
public void testWithAuthModeBasicAndNoPassword() throws ParseException {
140+
String noPasswordYAML = Paths.get(cliResourcesPath, "negative", "no-password.yaml").toString();
141+
String[] cliArgs = new String[] {
142+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noPasswordYAML
143+
};
144+
CLIProcessor.main(cliArgs);
145+
}
146+
147+
@Test(expectedExceptions = GeneratorException.class)
148+
public void testWithAuthModeBasicAndNoCredentials() throws ParseException {
149+
String noCredsYAML = Paths.get(cliResourcesPath, "negative", "no-credentials.yaml").toString();
150+
String[] cliArgs = new String[] {
151+
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noCredsYAML
152+
};
153+
CLIProcessor.main(cliArgs);
154+
}
53155
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
authMode: "SSO"
2+
username: "username"
3+
password: "password"
4+
grpchost: "localhost"
5+
grpcport: "3387"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
username: "username"
2+
password: "password"
3+
grpchost: "localhost"
4+
grpcport: "3387"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
authMode: "basic"
2+
grpchost: "localhost"
3+
grpcport: "3387"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
authMode: "basic"
2+
username: "username"
3+
restURL:
4+
baseURL: "http://localhost:3388"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
authMode: "basic"
2+
password: "password"
3+
restURL:
4+
baseURL: "http://localhost:3388"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
authMode: "none"
2+
username: "username"
3+
password: "password"
4+
grpchost: "localhost"
5+
grpcport: "3387"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
authMode: "basic"
2+
username: "username"
3+
password: "password"
4+
grpchost: "localhost"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
authMode: "basic"
2+
username: "username"
3+
password: "password"
4+
grpcport: "3387"

0 commit comments

Comments
 (0)