@Test public void testCreateBucket() throws Exception { doReturn(fakeProject).when(mockGet).execute(); when(mockGcsUtil.bucketOwner(any(GcsPath.class))).thenReturn(1L); String bucket = GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); assertEquals("gs://dataflow-staging-us-north1-1/temp/", bucket); }
@Test public void testProjectMismatch() throws Exception { doReturn(fakeProject).when(mockGet).execute(); when(mockGcsUtil.bucketOwner(any(GcsPath.class))).thenReturn(5L); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Bucket owner does not match the project"); GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); }
@Test public void testCannotGetBucketOwner() throws Exception { doReturn(fakeProject).when(mockGet).execute(); when(mockGcsUtil.bucketOwner(any(GcsPath.class))).thenThrow(new IOException("badness")); thrown.expect(RuntimeException.class); thrown.expectMessage("Unable to determine the owner"); GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); }
long owner = gcpOptions.getGcsUtil().bucketOwner(GcsPath.fromComponents(bucketName, "")); checkArgument( owner == projectNumber,