18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static com .google .common .truth .Truth .assertWithMessage ;
21
+ import static org .junit .Assert .assertEquals ;
21
22
22
23
import com .google .cloud .compute .v1 .AttachedDisk ;
23
24
import com .google .cloud .compute .v1 .AttachedDiskInitializeParams ;
46
47
import java .util .concurrent .ExecutionException ;
47
48
import java .util .concurrent .TimeUnit ;
48
49
import java .util .concurrent .TimeoutException ;
49
- import org .junit .Assert ;
50
50
import org .junit .jupiter .api .AfterAll ;
51
51
import org .junit .jupiter .api .AfterEach ;
52
52
import org .junit .jupiter .api .BeforeAll ;
@@ -77,6 +77,7 @@ public class DisksIT {
77
77
String .format ("projects/%s/zones/%s-a" , PROJECT_ID , REGION ),
78
78
String .format ("projects/%s/zones/%s-b" , PROJECT_ID , REGION ));
79
79
private static String SECONDARY_REGIONAL_DISK ;
80
+ private static String SECONDARY_DISK ;
80
81
private static final long DISK_SIZE = 10L ;
81
82
private ByteArrayOutputStream stdOut ;
82
83
@@ -107,14 +108,17 @@ public static void setup()
107
108
REGIONAL_BLANK_DISK = "gcloud-test-disk-rattach-" + uuid ;
108
109
REGIONAL_REPLICATED_DISK = "gcloud-test-disk-replicated-" + uuid ;
109
110
SECONDARY_REGIONAL_DISK = "gcloud-test-disk-secondary-regional-" + uuid ;
111
+ SECONDARY_DISK = "gcloud-test-disk-secondary-" + uuid ;
110
112
111
113
// Cleanup existing stale resources.
112
114
Util .cleanUpExistingInstances ("test-disks" , PROJECT_ID , ZONE );
113
115
Util .cleanUpExistingDisks ("gcloud-test-" , PROJECT_ID , ZONE );
114
- Util .cleanUpExistingRegionalDisks ("gcloud-test-disk-secondary-regional- " , PROJECT_ID , REGION );
115
- Util .cleanUpExistingRegionalDisks ("gcloud-test-disk-rattach-" , PROJECT_ID , REGION );
116
- Util . cleanUpExistingSnapshots ( "gcloud-test-snapshot- " , PROJECT_ID );
116
+ Util .cleanUpExistingDisks ("gcloud-test-" , PROJECT_ID , "us-central1-c" );
117
+ Util .cleanUpExistingRegionalDisks (
118
+ "gcloud-test-disk-secondary-regional- " , PROJECT_ID , "us-central1" );
117
119
Util .cleanUpExistingRegionalDisks ("gcloud-test-disk-" , PROJECT_ID , REGION );
120
+ Util .cleanUpExistingSnapshots ("gcloud-test-snapshot-" , PROJECT_ID );
121
+
118
122
// Create disk from image.
119
123
Image debianImage = null ;
120
124
try (ImagesClient imagesClient = ImagesClient .create ()) {
@@ -181,6 +185,7 @@ public static void cleanUp()
181
185
RegionalDelete .deleteRegionalDisk (PROJECT_ID , REGION , REGIONAL_BLANK_DISK );
182
186
RegionalDelete .deleteRegionalDisk (PROJECT_ID , REGION , REGIONAL_REPLICATED_DISK );
183
187
RegionalDelete .deleteRegionalDisk (PROJECT_ID , "us-central1" , SECONDARY_REGIONAL_DISK );
188
+ DeleteDisk .deleteDisk (PROJECT_ID , "us-central1-c" , SECONDARY_DISK );
184
189
185
190
stdOut .close ();
186
191
System .setOut (out );
@@ -285,7 +290,7 @@ public void testDiskAttachResize()
285
290
throws IOException , ExecutionException , InterruptedException , TimeoutException {
286
291
// Test disk attach.
287
292
Instance instance = Util .getInstance (PROJECT_ID , ZONE , INSTANCE_NAME );
288
- Assert . assertEquals (1 , instance .getDisksCount ());
293
+ assertEquals (1 , instance .getDisksCount ());
289
294
290
295
Disk zonalDisk = Util .getDisk (PROJECT_ID , ZONE , ZONAL_BLANK_DISK );
291
296
Disk regionalDisk = Util .getRegionalDisk (PROJECT_ID , REGION , REGIONAL_BLANK_DISK );
@@ -305,8 +310,8 @@ public void testDiskAttachResize()
305
310
ResizeRegionalDisk .resizeRegionalDisk (PROJECT_ID , regionalDisk .getRegion ().split ("regions/" )[1 ],
306
311
regionalDisk .getName (), 23 );
307
312
308
- Assert . assertEquals (22 , Util .getDisk (PROJECT_ID , ZONE , ZONAL_BLANK_DISK ).getSizeGb ());
309
- Assert . assertEquals (23 ,
313
+ assertEquals (22 , Util .getDisk (PROJECT_ID , ZONE , ZONAL_BLANK_DISK ).getSizeGb ());
314
+ assertEquals (23 ,
310
315
Util .getRegionalDisk (PROJECT_ID , REGION , REGIONAL_BLANK_DISK ).getSizeGb ());
311
316
}
312
317
@@ -315,8 +320,10 @@ public void testCreateReplicatedDisk()
315
320
throws IOException , ExecutionException , InterruptedException , TimeoutException {
316
321
Status status = CreateReplicatedDisk .createReplicatedDisk (PROJECT_ID , REGION ,
317
322
replicaZones , REGIONAL_REPLICATED_DISK , 100 , DISK_TYPE );
323
+ Disk disk = Util .getRegionalDisk (PROJECT_ID , REGION , REGIONAL_REPLICATED_DISK );
318
324
319
325
assertThat (status ).isEqualTo (Status .DONE );
326
+ assertEquals (REGIONAL_REPLICATED_DISK , disk .getName ());
320
327
}
321
328
322
329
@ Test
@@ -327,7 +334,23 @@ public void testCreateDiskSecondaryRegional()
327
334
Status status = CreateDiskSecondaryRegional .createDiskSecondaryRegional (
328
335
PROJECT_ID , PROJECT_ID , REGIONAL_BLANK_DISK , SECONDARY_REGIONAL_DISK ,
329
336
REGION , "us-central1" , DISK_SIZE , diskType );
337
+ Disk disk = Util .getRegionalDisk (PROJECT_ID , "us-central1" , SECONDARY_REGIONAL_DISK );
338
+
339
+ assertThat (status ).isEqualTo (Status .DONE );
340
+ assertEquals (SECONDARY_REGIONAL_DISK , disk .getName ());
341
+ }
342
+
343
+ @ Test
344
+ public void testCreateDiskSecondaryZonal ()
345
+ throws IOException , ExecutionException , InterruptedException , TimeoutException {
346
+ String diskType = String .format (
347
+ "projects/%s/zones/%s/diskTypes/pd-ssd" , PROJECT_ID , ZONE );
348
+ Status status = CreateDiskSecondaryZonal .createDiskSecondaryZonal (
349
+ PROJECT_ID , PROJECT_ID , EMPTY_DISK_NAME , SECONDARY_DISK , ZONE ,
350
+ "us-central1-c" , DISK_SIZE , diskType );
351
+ Disk disk = Util .getDisk (PROJECT_ID , "us-central1-c" , SECONDARY_DISK );
330
352
331
353
assertThat (status ).isEqualTo (Status .DONE );
354
+ assertEquals (SECONDARY_DISK , disk .getName ());
332
355
}
333
356
}
0 commit comments