use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstanceTest method absoluteWorkingDirectoryIsInvalid.
@Test
public void absoluteWorkingDirectoryIsInvalid() {
AbstractServerInstance instance = new DummyServerInstance();
PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
instance.validateCommand(Command.newBuilder().addArguments("foo").setWorkingDirectory("/var/lib/db").build(), DIGEST_UTIL.empty(), ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of(), preconditionFailureBuilder);
PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
Violation violation = preconditionFailure.getViolationsList().get(0);
assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
assertThat(violation.getSubject()).isEqualTo(INVALID_COMMAND);
assertThat(violation.getDescription()).isEqualTo("working directory is absolute");
}
use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstanceTest method duplicateDirectoryInputIsInvalid.
@Test
public void duplicateDirectoryInputIsInvalid() {
Directory emptyDirectory = Directory.getDefaultInstance();
Digest emptyDirectoryDigest = DIGEST_UTIL.compute(emptyDirectory);
PreconditionFailure.Builder preconditionFailure = PreconditionFailure.newBuilder();
AbstractServerInstance.validateActionInputDirectory(ACTION_INPUT_ROOT_DIRECTORY_PATH, Directory.newBuilder().addAllDirectories(ImmutableList.of(DirectoryNode.newBuilder().setName("foo").setDigest(emptyDirectoryDigest).build(), DirectoryNode.newBuilder().setName("foo").setDigest(emptyDirectoryDigest).build())).build(), /* pathDigests=*/
new Stack<>(), /* visited=*/
Sets.newHashSet(), /* directoriesIndex=*/
ImmutableMap.of(emptyDirectoryDigest, emptyDirectory), /* onInputFiles=*/
file -> {
}, /* onInputDirectories=*/
directory -> {
}, /* onInputDigests=*/
digest -> {
}, preconditionFailure);
assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
Violation violation = preconditionFailure.getViolationsList().get(0);
assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
assertThat(violation.getSubject()).isEqualTo("/: foo");
assertThat(violation.getDescription()).isEqualTo(DUPLICATE_DIRENT);
}
use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstanceTest method nestedOutputDirectoriesAreInvalid.
@Test
public void nestedOutputDirectoriesAreInvalid() {
PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
AbstractServerInstance.validateOutputs(ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of("foo", "foo/bar"), preconditionFailureBuilder);
PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
Violation violation = preconditionFailure.getViolationsList().get(0);
assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
assertThat(violation.getSubject()).isEqualTo("foo");
assertThat(violation.getDescription()).isEqualTo(OUTPUT_DIRECTORY_IS_OUTPUT_ANCESTOR);
}
use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstanceTest method outputDirectoriesContainingOutputFilesAreInvalid.
@Test
public void outputDirectoriesContainingOutputFilesAreInvalid() {
PreconditionFailure.Builder preconditionFailureBuilder = PreconditionFailure.newBuilder();
AbstractServerInstance.validateOutputs(ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of("foo/bar"), ImmutableSet.of("foo"), preconditionFailureBuilder);
PreconditionFailure preconditionFailure = preconditionFailureBuilder.build();
assertThat(preconditionFailure.getViolationsCount()).isEqualTo(1);
Violation violation = preconditionFailure.getViolationsList().get(0);
assertThat(violation.getType()).isEqualTo(VIOLATION_TYPE_INVALID);
assertThat(violation.getSubject()).isEqualTo("foo");
assertThat(violation.getDescription()).isEqualTo(OUTPUT_DIRECTORY_IS_OUTPUT_ANCESTOR);
}
use of com.google.rpc.PreconditionFailure in project bazel-buildfarm by bazelbuild.
the class Cat method printStatus.
private static void printStatus(com.google.rpc.Status status) throws InvalidProtocolBufferException {
System.out.println(" Code: " + Code.forNumber(status.getCode()));
if (!status.getMessage().isEmpty()) {
System.out.println(" Message: " + status.getMessage());
}
if (status.getDetailsCount() > 0) {
System.out.println(" Details:");
for (Any detail : status.getDetailsList()) {
if (detail.is(RetryInfo.class)) {
RetryInfo retryInfo = detail.unpack(RetryInfo.class);
System.out.println(" RetryDelay: " + (retryInfo.getRetryDelay().getSeconds() + retryInfo.getRetryDelay().getNanos() / 1000000000.0f));
} else if (detail.is(PreconditionFailure.class)) {
PreconditionFailure preconditionFailure = detail.unpack(PreconditionFailure.class);
System.out.println(" PreconditionFailure:");
for (PreconditionFailure.Violation violation : preconditionFailure.getViolationsList()) {
System.out.println(" Violation: " + violation.getType());
System.out.println(" Subject: " + violation.getSubject());
System.out.println(" Description: " + violation.getDescription());
}
} else {
System.out.println(" Unknown Detail: " + detail.getTypeUrl());
}
}
}
}
Aggregations