use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testSetValueHasMultipleValuesButFlagIsNotMultiple.
@Test
public void testSetValueHasMultipleValuesButFlagIsNotMultiple() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName(// Not repeatable flag.
"test_string").getSetValueBuilder().addFlagValue(// Has multiple values.
"policy value 1").addFlagValue("policy value 2");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
// expected.
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testDisallowValuesDisallowsValue.
@Test
public void testDisallowValuesDisallowsValue() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getDisallowValuesBuilder().addDisallowedValues("foo").addDisallowedValues("bar");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_string=foo");
// Option should be "foo" as specified by the user.
TestOptions testOptions = getTestOptions();
assertEquals("foo", testOptions.testString);
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
// expected, since foo is disallowed.
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testAllowValuesDisallowsValue.
@Test
public void testAllowValuesDisallowsValue() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getAllowValuesBuilder().addAllowedValues(STRING_FLAG_DEFAULT).addAllowedValues("bar");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_string=foo");
// Option should be "foo" as specified by the user.
TestOptions testOptions = getTestOptions();
assertEquals("foo", testOptions.testString);
try {
// Should throw because "foo" is not allowed.
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
// expected
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testDisallowValuesDisallowsListConverterFlag.
@Test
public void testDisallowValuesDisallowsListConverterFlag() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_list_converters").getDisallowValuesBuilder().addDisallowedValues("a");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_list_converters=a,b,c");
TestOptions testOptions = getTestOptions();
assertEquals(Arrays.asList("a", "b", "c"), testOptions.testListConverters);
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
assertThat(e.getMessage()).contains("Flag value 'a' for flag 'test_list_converters' is not allowed by invocation policy");
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testAllowValuesDisallowsListConverterFlagValues.
@Test
public void testAllowValuesDisallowsListConverterFlagValues() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_list_converters").getAllowValuesBuilder().addAllowedValues("a");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_list_converters=a,b,c");
TestOptions testOptions = getTestOptions();
assertEquals(Arrays.asList("a", "b", "c"), testOptions.testListConverters);
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
assertThat(e.getMessage()).contains("Flag value 'b' for flag 'test_list_converters' is not allowed by invocation policy");
}
}
Aggregations