Skip to content

Commit

Permalink
TS-31571 Test fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
stahlbauer committed Nov 5, 2024
1 parent 9d98f3c commit 1a36e4c
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
public class AgentOptionsParserTest {

private TeamscaleCredentials teamscaleCredentials;
private final AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, null, null);
private Path configFile;
/** The mock server to run requests against. */
protected MockWebServer mockWebServer;
Expand Down Expand Up @@ -104,7 +103,7 @@ public void environmentConfigIdOverridesCommandLineOptions() throws Exception {
mockWebServer.enqueue(new MockResponse().setBody(JsonUtils.serialize(registration)));
AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), "my-config",
null, teamscaleCredentials);
AgentOptions options = parseAndThrow("teamscale-partition=bar");
AgentOptions options = parseAndThrow(parser, "teamscale-partition=bar");

assertThat(options.teamscaleServer.partition).isEqualTo("foo");
}
Expand All @@ -113,7 +112,7 @@ public void environmentConfigIdOverridesCommandLineOptions() throws Exception {
public void environmentConfigFileOverridesCommandLineOptions() throws Exception {
AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, configFile.toString(),
teamscaleCredentials);
AgentOptions options = parseAndThrow("teamscale-partition=from-command-line");
AgentOptions options = parseAndThrow(parser, "teamscale-partition=from-command-line");

assertThat(options.teamscaleServer.partition).isEqualTo("from-config-file");
}
Expand All @@ -128,7 +127,7 @@ public void environmentConfigFileOverridesConfigId() throws Exception {
mockWebServer.enqueue(new MockResponse().setBody(JsonUtils.serialize(registration)));
AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), "my-config", configFile.toString(),
teamscaleCredentials);
AgentOptions options = parseAndThrow("teamscale-partition=from-command-line");
AgentOptions options = parseAndThrow(parser, "teamscale-partition=from-command-line");

assertThat(options.teamscaleServer.partition).isEqualTo("from-config-file");
}
Expand Down Expand Up @@ -232,21 +231,24 @@ public void mustPreserveDefaultExcludes() throws Exception {

@Test
public void teamscalePropertiesCredentialsUsedAsDefaultButOverridable() throws Exception {
AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, null, teamscaleCredentials);

assertThat(parseAndThrow("teamscale-project=p,teamscale-partition=p").teamscaleServer.userName).isEqualTo(
assertThat(parseAndThrow(new AgentOptionsParser(new CommandLineLogger(), null, null, teamscaleCredentials), "teamscale-project=p,teamscale-partition=p").teamscaleServer.userName).isEqualTo(
"user");
assertThat(parseAndThrow(
assertThat(parseAndThrow(new AgentOptionsParser(new CommandLineLogger(), null, null, teamscaleCredentials),
"teamscale-project=p,teamscale-partition=p,teamscale-user=user2").teamscaleServer.userName).isEqualTo(
"user2");
}

private AgentOptions parseAndThrow(String options) throws Exception {
private AgentOptions parseAndThrow(AgentOptionsParser parser, String options) throws Exception {
AgentOptions result = parser.parse(options);
parser.throwOnCollectedErrors();
return result;
}

private AgentOptions parseAndThrow(String options) throws Exception {
AgentOptionsParser parser = new AgentOptionsParser(new CommandLineLogger(), null, null, null);
return parseAndThrow(parser, options);
}

/**
* Delete created coverage folders
*/
Expand Down

0 comments on commit 1a36e4c

Please sign in to comment.