Skip to content

Commit

Permalink
Write test run config into yaml file for reproducing (#60)
Browse files Browse the repository at this point in the history
Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys authored Jan 15, 2024
1 parent 313175d commit 6edef55
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ GITHUB_TOKEN="your_github_read_token" mvn verify -Pupgrade
```commandline
GITHUB_TOKEN="your_github_read_token" mvn test
```

## Reproducing test run
When every test run is executed, test suite automatically creates a `config.yaml` file
which contains all configured environment variables. Location of config file
is `$LOG_DIR/test-run-YYYY-MM-DD_HH-mm/config.yaml` where `$LOG_DIR` is by
default `${repo_root}/target/logs`.

```commandline
GITHUB_TOKEN="your_github_read_token" ENV_FILE=path_to_file/config.yaml mvn verify -Psmoke
```
36 changes: 36 additions & 0 deletions src/main/java/io/odh/test/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
import io.odh.test.install.InstallTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
Expand Down Expand Up @@ -109,6 +113,11 @@ private Environment() {
}
});
LoggerUtils.logSeparator("-", 30);
try {
saveConfigurationFile();
} catch (IOException e) {
LOGGER.warn("Yaml configuration can't be saved");
}
}

public static void print() {
Expand Down Expand Up @@ -144,4 +153,31 @@ private static Map<String, Object> loadConfigurationFile() {
return Collections.emptyMap();
}
}

private static void saveConfigurationFile() throws IOException {
Path logPath = Environment.LOG_DIR;
Files.createDirectories(logPath);

LinkedHashMap<String, String> toSave = new LinkedHashMap<>();

VALUES.forEach((key, value) -> {
if (isWriteable(key, value)) {
toSave.put(key, value);
}
});

PrintWriter writer = new PrintWriter(logPath.resolve("config.yaml").toFile());
final DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml yaml = new Yaml(options);
yaml.dump(toSave, writer);
}

private static boolean isWriteable(String var, String value) {
return !value.equals("null")
&& !var.equals(CONFIG_FILE_PATH_ENV)
&& !var.equals(USER_PATH)
&& !value.equals("USER");
}
}

0 comments on commit 6edef55

Please sign in to comment.