Skip to content

Commit 3bb9772

Browse files
authored
Do not build Docker image on each test (#84)
* Do not build Docker image on each test * Prefer test config from environment
1 parent e893304 commit 3bb9772

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

.github/workflows/maven.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ jobs:
3232
TEST_CONFIGURATION_ACCESS_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }}
3333
run: mvn test
3434

35-
- name: Build the Docker image
36-
run: docker build . --file Dockerfile
35+
# TODO: Move to pack.yml
36+
# - name: Build the Docker image
37+
# run: docker build . --file Dockerfile

src/main/java/com/aspose/barcode/cloud/ApiClient.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,8 @@ public void requestToken() throws ApiException {
956956

957957
Response response = httpClient.newCall(request).execute();
958958
if (response.code() != 200) {
959-
throw new ApiException("Error fetching token: " + response.message(), response.code());
959+
throw new ApiException(
960+
"Error fetching token: " + response.message(), response.code());
960961
}
961962
GetAccessTokenResult result =
962963
json.deserialize(response.body().string(), GetAccessTokenResult.class);

src/test/java/com/aspose/barcode/cloud/test/TestConfiguration.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.aspose.barcode.cloud.Configuration;
44

5-
import java.io.File;
65
import java.io.IOException;
76
import java.nio.file.Path;
87
import java.nio.file.Paths;
@@ -11,16 +10,21 @@ public class TestConfiguration {
1110
private static final Path ConfigFileName = Paths.get("src", "test", "configuration.json");
1211

1312
public static Configuration load() {
14-
File maybeConfigFile = ConfigFileName.toFile();
15-
if (maybeConfigFile.exists()) {
16-
try {
17-
return Configuration.loadFromFile(maybeConfigFile);
18-
} catch (IOException ignored) {
19-
}
13+
String maybeToken = System.getenv().get("TEST_CONFIGURATION_ACCESS_TOKEN");
14+
15+
// Prefer config from environment
16+
if (maybeToken != null && !maybeToken.isEmpty()) {
17+
Configuration fromEnv = new Configuration();
18+
fromEnv.AccessToken = maybeToken;
19+
return fromEnv;
2020
}
2121

22-
Configuration fromEnv = new Configuration();
23-
fromEnv.AccessToken = System.getenv().get("TEST_CONFIGURATION_ACCESS_TOKEN");
24-
return fromEnv;
22+
// And then try to load config from file
23+
try {
24+
return Configuration.loadFromFile(ConfigFileName.toFile());
25+
} catch (IOException e) {
26+
System.err.println("ERROR: Cannot load config from file " + ConfigFileName);
27+
throw new RuntimeException(e);
28+
}
2529
}
2630
}

0 commit comments

Comments
 (0)