Throw error when envvar is missing and provide unit tests

This commit is contained in:
Dave Fisher 2024-07-18 11:07:30 -07:00
parent fca6971316
commit 1ff76aebd4
5 changed files with 18 additions and 1 deletions

View File

@ -573,6 +573,9 @@
</includes>
<useSystemClassLoader>false
</useSystemClassLoader> <!-- fixes reflection tests -->
<environmentVariables>
<TEST_ENV_VAR>value</TEST_ENV_VAR>
</environmentVariables>
</configuration>
</plugin>

View File

@ -169,8 +169,9 @@ public class NBAtFile {
String word = iter.next();
String modified = word.replaceAll("\\$\\{DIR}",parent.toString());
Optional<String> interpolatedString = NBEnvironment.INSTANCE.interpolate(modified);
String value = interpolatedString.orElseThrow(() -> new RuntimeException("Unable to find environment variable or property in text '"+modified+"' in atfile '" + atPath + "'"));
iter.remove();
iter.add(interpolatedString.orElse(""));
iter.add(value);
}
return formatted;
}

View File

@ -91,4 +91,15 @@ class NBAtFileTest {
assertThat(strings).containsExactly("arg1","arg1","arg1","arg2","arg3","arg3","arg3","deepval");
}
@Test
public void testAtfileEnvironmentVariable() {
LinkedList<String> strings = NBAtFile.includeAt("@src/test/resources/atfiles/environment_variable.yaml");
assertThat(strings).containsExactly("My value environment");
}
@Test
public void testAtfileMissingEnvironmentVariable() {
assertThrows(RuntimeException.class, () -> NBAtFile.includeAt("@src/test/resources/atfiles/environment_variable_missing.yaml:>:"));
}
}

View File

@ -0,0 +1 @@
- My ${MISSING_ENV_VAR} environment

View File

@ -0,0 +1 @@
- My ${TEST_ENV_VAR} environment