Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public VisualRegressionTrackerConfig(@NonNull String apiUrl, @NonNull String api
this(apiUrl, apiKey, project, branchName, ciBuildId, enableSoftAssert, httpTimeoutInSeconds, null);
}

public String getApiUrl() {
return apiUrl.replaceAll("/+$", "");
}

public static VisualRegressionTrackerConfigBuilder builder() {
return new VisualRegressionTrackerConfigBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.visual_regression_tracker.sdk_java;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Callable;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -175,6 +177,27 @@ public void shouldKeepTheConstructorWithoutSourceBranch() {
assertThat(config.getSourceBranch(), is((String) null));
}

@DataProvider(name = "apiUrlSources")
public Object[][] apiUrlSources() {
return new Object[][]{
{(Callable<VisualRegressionTrackerConfig>) () ->
new VisualRegressionTrackerConfig("http://localhost:4200/", "KEY", "PROJECT")},
{(Callable<VisualRegressionTrackerConfig>) () -> VisualRegressionTrackerConfig.builder()
.apiUrl("http://localhost:4200//").apiKey("KEY").project("PROJECT").build()},
{(Callable<VisualRegressionTrackerConfig>) () -> new EnvironmentVariables("VRT_APIURL", "http://localhost:4200/")
.set("VRT_APIKEY", "KEY").set("VRT_PROJECT", "PROJECT")
.execute(() -> VisualRegressionTrackerConfig.builder().build())},
{(Callable<VisualRegressionTrackerConfig>) () -> VisualRegressionTrackerConfig.builder()
.configFile(configFile("{\"apiUrl\": \"http://localhost:4200/\", \"apiKey\": \"KEY\", \"project\": \"PROJECT\"}"))
.build()},
};
}

@Test(dataProvider = "apiUrlSources")
public void shouldStripTrailingSlashesFromApiUrl(Callable<VisualRegressionTrackerConfig> source) throws Exception {
assertThat(source.call().getApiUrl(), is("http://localhost:4200"));
}

private File configFile(String content) throws Exception {
Path configFile = Files.createTempFile("vrt", ".json");
Files.writeString(configFile, content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void shouldStartBuild() throws IOException, InterruptedException {
BuildResponse result = vrt.start();

RecordedRequest recordedRequest = mockWebServer.takeRequest();
assertThat(recordedRequest.getPath(), is("/builds"));
assertThat(recordedRequest.getHeader(VisualRegressionTracker.API_KEY_HEADER), is(config.getApiKey()));
assertThat(recordedRequest.getHeader(VisualRegressionTracker.PROJECT_HEADER), is(config.getProject()));
assertThat(recordedRequest.getBody().readUtf8(), is(gson.toJson(buildRequest)));
Expand Down
Loading