Skip to content

Instantly share code, notes, and snippets.

@rahogata
Created April 5, 2023 11:43
Show Gist options
  • Save rahogata/77a8723f701eb30387a6edffbcf47963 to your computer and use it in GitHub Desktop.
Save rahogata/77a8723f701eb30387a6edffbcf47963 to your computer and use it in GitHub Desktop.
Create application.yaml for unit tests, avoiding copy of main application.yaml.
service.doc:
dest-directory: file:./service-files
temp-dir: file:./service-files/service-temp-dir
service.storage.location: ./ssfiles
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.DumperOptions
task mergeToTestApplicationConfig {
InputStream appIns = new File("${projectDir}/src/main/resources/application.yaml").newInputStream()
InputStream testIns = new File("${projectDir}/src/test/resources/application-sibling.yaml").newInputStream()
InputStream appTestIns = new SequenceInputStream(appIns, testIns);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml p = new Yaml()
def mergedOut = p.load(appTestIns)
p.dump(mergedOut, new FileWriter("${projectDir}/src/test/resources/application.yaml"))
}
tasks.test.dependsOn mergeToTestApplicationConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment