Skip to content

Commit

Permalink
Validates that input and output GCS paths specify a bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
jkff committed Apr 19, 2017
1 parent 29e054a commit 529cbd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public String validateOutputFilePrefixSupported(String filePrefix) {
public String verifyPath(String path) {
GcsPath gcsPath = getGcsPath(path);
checkArgument(gcsPath.isAbsolute(), "Must provide absolute paths for Dataflow");
checkArgument(!gcsPath.getObject().isEmpty(),
"Missing object or bucket in path: '%s', did you mean: 'gs://some-bucket/%s'?",
gcsPath, gcsPath.getBucket());
checkArgument(!gcsPath.getObject().contains("//"),
"Dataflow Service does not allow objects with consecutive slashes");
return gcsPath.toResourceName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public void testInvalidFilePattern() {
validator.validateInputFilePatternSupported("/local/path");
}

@Test
public void testFilePatternMissingBucket() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
"Missing object or bucket in path: 'gs://input/', "
+ "did you mean: 'gs://some-bucket/input'?");
validator.validateInputFilePatternSupported("gs://input");
}

@Test
public void testWhenBucketDoesNotExist() throws Exception {
when(mockGcsUtil.bucketAccessible(any(GcsPath.class))).thenReturn(false);
Expand All @@ -84,4 +93,13 @@ public void testInvalidOutputPrefix() {
"Expected a valid 'gs://' path but was given '/local/path'");
validator.validateOutputFilePrefixSupported("/local/path");
}

@Test
public void testOutputPrefixMissingBucket() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
"Missing object or bucket in path: 'gs://output/', "
+ "did you mean: 'gs://some-bucket/output'?");
validator.validateOutputFilePrefixSupported("gs://output");
}
}

0 comments on commit 529cbd7

Please sign in to comment.