Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NoamShaish authored and Dorin Popa committed Apr 18, 2023
1 parent 9386eb9 commit 7a1e1c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,17 @@ public boolean emitBounds() {
*/
@Override
protected InfluxDB createClient(String server, int port, String prefix) {
String protocol = useHttps ? "https" : "http";
String url = String.format("%s://%s:%d", protocol, server, port);
String url = resolveUrl(server, port);
logInfo(String.format("Connecting to influxDB at %s", url));

return InfluxDBFactory.connect(url, username, password);
}

public String resolveUrl(String server, int port) {
String protocol = useHttps ? "https" : "http";
return String.format("%s://%s:%d", protocol, server, port);
}

private void logInfo(String message) {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,22 @@ public void testRecordGaugeValue() {
Mockito.doAnswer(answer).when(client).write(Matchers.any(BatchPoints.class));
reporter.recordGaugeValue("fake", 100L);
}

@Test
public void testHttpsUrlResolution() {
Arguments arguments = MockArguments.createArgs("localhost", 443, "influxdb.reporter.test",
ImmutableMap.of("username", "user", "password", "password", "database", "database", "useHttps", "true"));
InfluxDBReporter reporter = new InfluxDBReporter(arguments);

assertEquals(reporter.resolveUrl("localhost", 443), "https://localhost:443");
}

@Test
public void testHttpUrlResolution() {
Arguments arguments = MockArguments.createArgs("localhost", 8888, "influxdb.reporter.test",
ImmutableMap.of("username", "user", "password", "password", "database", "database", "useHttps", "false"));
InfluxDBReporter reporter = new InfluxDBReporter(arguments);

assertEquals(reporter.resolveUrl("localhost", 8888), "http://localhost:8888");
}
}

0 comments on commit 7a1e1c7

Please sign in to comment.