Skip to content

Commit

Permalink
Additional test case and error message refinement
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 682818292
  • Loading branch information
TristonianJones authored and copybara-github committed Oct 6, 2024
1 parent 2f6f308 commit 0da0145
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private CelPolicyConfig parseYaml(String source, String description)
.orElseThrow(
() ->
new CelPolicyValidationException(
String.format("YAML document is malformed: %s", source)));
String.format("YAML document empty or malformed: %s", source)));
node = yamlNode;
} catch (RuntimeException e) {
throw new CelPolicyValidationException("YAML document is malformed: " + e.getMessage(), e);
Expand Down
3 changes: 2 additions & 1 deletion policy/src/main/java/dev/cel/policy/CelPolicyYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ private CelPolicy parseYaml() throws CelPolicyValidationException {
.orElseThrow(
() ->
new CelPolicyValidationException(
String.format("YAML document is malformed: %s", policySourceString)));
String.format(
"YAML document empty or malformed: %s", policySourceString)));
node = yamlNode;
} catch (RuntimeException e) {
throw new CelPolicyValidationException("YAML document is malformed: " + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public final class CelPolicyYamlConfigParserTest {
private static final CelPolicyConfigParser POLICY_CONFIG_PARSER =
CelPolicyParserFactory.newYamlConfigParser();

@Test
public void config_setEmpty() throws Exception {
assertThrows(CelPolicyValidationException.class, () -> POLICY_CONFIG_PARSER.parse(""));
}

@Test
public void config_setBasicProperties() throws Exception {
String yamlConfig = "name: hello\n" + "description: empty\n" + "container: pb.pkg\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public void parseYamlPolicy_success(@TestParameter TestYamlPolicy yamlPolicy) th
assertThat(policy.policySource().getDescription()).isEqualTo(description);
}

@Test
public void parser_setEmpty() throws Exception {
assertThrows(CelPolicyValidationException.class, () -> POLICY_PARSER.parse("", ""));
}

@Test
public void parseYamlPolicy_withExplanation() throws Exception {
String policySource =
Expand Down

0 comments on commit 0da0145

Please sign in to comment.