Skip to content

Commit

Permalink
Merge pull request #63 from cisco-open/fix/v0.9.0/add-cli-tests
Browse files Browse the repository at this point in the history
Add tests for the CLI mode
  • Loading branch information
preet-dev authored Dec 22, 2022
2 parents e5fdb0c + 2f63377 commit 646aeb1
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ private static PayloadHandler getPayloadHandler(String targetEnvYAML) {
"must be provided in environment target YAML");
}
AuthHandler authHandler;
if (targetEnvironmentDetails.getAuthMode() == null) {
throw new GeneratorException("Missing authMode in environment target YAML");
}
if (!(targetEnvironmentDetails.getAuthMode().equalsIgnoreCase("NONE") ||
targetEnvironmentDetails.getAuthMode().equalsIgnoreCase("BASIC"))) {
throw new GeneratorException("Invalid authMode in environment target YAML. Allowed - NONE, BASIC");
}
if (targetEnvironmentDetails.getAuthMode().equalsIgnoreCase("NONE")) {
authHandler = new NoAuthHandler();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.opentelemetry.contrib.generator.telemetry;

import io.opentelemetry.contrib.generator.core.exception.GeneratorException;
import io.opentelemetry.contrib.generator.telemetry.cli.CLIProcessor;
import org.apache.commons.cli.MissingOptionException;
import org.apache.commons.cli.ParseException;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -50,4 +52,104 @@ public void testMetricsTracesBasicAuthGRPC() throws ParseException {
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = MissingOptionException.class)
public void testWithoutEntityDefinition() throws ParseException {
String noAuthTargetYAML = Paths.get(cliResourcesPath, "target-noauth.yaml").toString();
String[] cliArgs = new String[] { METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noAuthTargetYAML };
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithOnlyEntityDefinition() throws ParseException {
String noAuthTargetYAML = Paths.get(cliResourcesPath, "target-noauth.yaml").toString();
String[] cliArgs = new String[] { "-e", ENTITIES_YAML, "-t", noAuthTargetYAML };
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = MissingOptionException.class)
public void testWithoutTargetAuthYAML() throws ParseException {
String[] cliArgs = new String[] { "-e", ENTITIES_YAML, METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML };
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithoutAuthMode() throws ParseException {
String noAuthModeYAML = Paths.get(cliResourcesPath, "negative", "no-auth-mode.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noAuthModeYAML
};
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithInvalidAuthMode() throws ParseException {
String invalidAuthModeYAML = Paths.get(cliResourcesPath, "negative", "invalid-auth-mode.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", invalidAuthModeYAML
};
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithoutEndpoint() throws ParseException {
String noEndpointYAML = Paths.get(cliResourcesPath, "negative", "without-endpoint.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noEndpointYAML
};
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithOnlyGRPCHost() throws ParseException {
String onlyGRPCHostYAML = Paths.get(cliResourcesPath, "negative", "only-grpc-host.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", onlyGRPCHostYAML
};
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithOnlyGRPCPort() throws ParseException {
String onlyGRPCPortYAML = Paths.get(cliResourcesPath, "negative", "only-grpc-port.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", onlyGRPCPortYAML
};
CLIProcessor.main(cliArgs);
}

@Test
public void testWithAuthModeNoneAndBasicCredentials() throws ParseException {
String noneAuthModeYAML = Paths.get(cliResourcesPath, "negative", "none-auth-mode.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noneAuthModeYAML
};
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithAuthModeBasicAndNoUsername() throws ParseException {
String noUsernameYAML = Paths.get(cliResourcesPath, "negative", "no-username.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noUsernameYAML
};
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithAuthModeBasicAndNoPassword() throws ParseException {
String noPasswordYAML = Paths.get(cliResourcesPath, "negative", "no-password.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noPasswordYAML
};
CLIProcessor.main(cliArgs);
}

@Test(expectedExceptions = GeneratorException.class)
public void testWithAuthModeBasicAndNoCredentials() throws ParseException {
String noCredsYAML = Paths.get(cliResourcesPath, "negative", "no-credentials.yaml").toString();
String[] cliArgs = new String[] {
"-e", ENTITIES_YAML, "-m", METRICS_YAML, "-l", LOGS_YAML, "-s", TRACES_YAML, "-t", noCredsYAML
};
CLIProcessor.main(cliArgs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
authMode: "SSO"
username: "username"
password: "password"
grpchost: "localhost"
grpcport: "3387"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
username: "username"
password: "password"
grpchost: "localhost"
grpcport: "3387"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
authMode: "basic"
grpchost: "localhost"
grpcport: "3387"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
authMode: "basic"
username: "username"
restURL:
baseURL: "http://localhost:3388"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
authMode: "basic"
password: "password"
restURL:
baseURL: "http://localhost:3388"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
authMode: "none"
username: "username"
password: "password"
grpchost: "localhost"
grpcport: "3387"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
authMode: "basic"
username: "username"
password: "password"
grpchost: "localhost"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
authMode: "basic"
username: "username"
password: "password"
grpcport: "3387"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
authMode: "basic"
username: "username"
password: "password"

0 comments on commit 646aeb1

Please sign in to comment.