@@ -309,16 +309,20 @@ public void testGCFResourceWithCloudRunAttributesSucceeds() {
309309 /** Google App Engine Tests * */
310310 @ ParameterizedTest
311311 @ MethodSource ("provideGAEVariantEnvironmentVariable" )
312- public void testGAEResourceWithAppEngineAttributesSucceeds (String gaeEnvironmentVar ) {
312+ public void testGAEResourceWithAppEngineAttributesSucceeds (
313+ String gaeEnvironmentVar ,
314+ String metadataZone ,
315+ String expectedZone ,
316+ String metadataRegion ,
317+ String expectedRegion ) {
313318 envVars .put ("GAE_SERVICE" , "app-engine-hello" );
314319 envVars .put ("GAE_VERSION" , "app-engine-hello-v1" );
315320 envVars .put ("GAE_INSTANCE" , "app-engine-hello-f236d" );
316321 envVars .put ("GAE_ENV" , gaeEnvironmentVar );
317322
318323 TestUtils .stubEndpoint ("/project/project-id" , "GAE-pid" );
319- // for standard, the region should be extracted from region attribute
320- TestUtils .stubEndpoint ("/instance/zone" , "country-region-zone" );
321- TestUtils .stubEndpoint ("/instance/region" , "country-region1" );
324+ TestUtils .stubEndpoint ("/instance/zone" , metadataZone );
325+ TestUtils .stubEndpoint ("/instance/region" , metadataRegion );
322326 TestUtils .stubEndpoint ("/instance/id" , "GAE-instance-id" );
323327
324328 EnvironmentVariables mockEnv = new EnvVarMock (envVars );
@@ -332,27 +336,47 @@ public void testGAEResourceWithAppEngineAttributesSucceeds(String gaeEnvironment
332336 new GoogleAppEngine (mockEnv , mockMetadataConfig ).getAttributes (), detectedAttributes );
333337 assertEquals ("GAE-pid" , detector .detectPlatform ().getProjectId ());
334338 assertEquals (5 , detectedAttributes .size ());
335-
336- if (gaeEnvironmentVar != null && gaeEnvironmentVar .equals ("standard" )) {
337- assertEquals (
338- "country-region1" , detector .detectPlatform ().getAttributes ().get (GAE_CLOUD_REGION ));
339- } else {
340- assertEquals (
341- "country-region" , detector .detectPlatform ().getAttributes ().get (GAE_CLOUD_REGION ));
342- }
339+ assertEquals (expectedRegion , detector .detectPlatform ().getAttributes ().get (GAE_CLOUD_REGION ));
343340 assertEquals ("app-engine-hello" , detectedAttributes .get (GAE_MODULE_NAME ));
344341 assertEquals ("app-engine-hello-v1" , detectedAttributes .get (GAE_APP_VERSION ));
345342 assertEquals ("app-engine-hello-f236d" , detectedAttributes .get (GAE_INSTANCE_ID ));
346- assertEquals ("country-region-zone" , detectedAttributes .get (GAE_AVAILABILITY_ZONE ));
343+ assertEquals (expectedZone , detectedAttributes .get (GAE_AVAILABILITY_ZONE ));
347344 }
348345
349- // Provides key-value pair of GAE variant environment and the expected region
350- // value based on the environment variable
346+ private static Arguments gaeTestArguments (
347+ String gaeEnvironmentVar ,
348+ String metadataZone ,
349+ String expectedZone ,
350+ String metadataRegion ,
351+ String expectedRegion ) {
352+ return Arguments .of (
353+ gaeEnvironmentVar , metadataZone , expectedZone , metadataRegion , expectedRegion );
354+ }
355+
356+ // Provides parameterized arguments for testGAEResourceWithAppEngineAttributesSucceeds
351357 private static Stream <Arguments > provideGAEVariantEnvironmentVariable () {
358+
352359 return Stream .of (
353- Arguments .of ("standard" ),
354- Arguments .of ((String ) null ),
355- Arguments .of ("flex" ),
356- Arguments .of ("" ));
360+ // GAE standard
361+ gaeTestArguments (
362+ "standard" ,
363+ // the zone should be extracted from the zone attribute
364+ "projects/233510669999/zones/us15" ,
365+ "us15" ,
366+ // the region should be extracted from region attribute
367+ "projects/233510669999/regions/us-central1" ,
368+ "us-central1" ),
369+
370+ // GAE flex
371+ gaeTestArguments (
372+ (String ) null ,
373+ "country-region-zone" ,
374+ "country-region-zone" ,
375+ // the region should be extracted from the zone attribute
376+ "" ,
377+ "country-region" ),
378+ gaeTestArguments (
379+ "flex" , "country-region-zone" , "country-region-zone" , "" , "country-region" ),
380+ gaeTestArguments ("" , "country-region-zone" , "country-region-zone" , "" , "country-region" ));
357381 }
358382}
0 commit comments