36
36
import org .mockito .Mockito ;
37
37
38
38
@ RunWith (JUnit4 .class )
39
- public class GCPResourceTest {
39
+ public class GCPResourceDetectorTest {
40
40
@ Rule public final WireMockRule wireMockRule = new WireMockRule (8089 );
41
41
private final GCPMetadataConfig metadataConfig = new GCPMetadataConfig ("http://localhost:8089/" );
42
42
private static final Map <String , String > envVars = new HashMap <>();
@@ -52,15 +52,16 @@ public void findsWithServiceLoader() {
52
52
ServiceLoader .load (ResourceProvider .class , getClass ().getClassLoader ());
53
53
assertTrue (
54
54
"Could not load GCP Resource detector using serviceloader, found: " + services ,
55
- services .stream ().anyMatch (provider -> provider .type ().equals (GCPResource .class )));
55
+ services .stream ().anyMatch (provider -> provider .type ().equals (GCPResourceDetector .class )));
56
56
}
57
57
58
58
@ Test
59
59
public void testGCPComputeResourceNotGCP () {
60
60
GCPMetadataConfig mockMetadataConfig = Mockito .mock (GCPMetadataConfig .class );
61
61
Mockito .when (mockMetadataConfig .isRunningOnGcp ()).thenReturn (false );
62
62
63
- GCPResource testResource = new GCPResource (mockMetadataConfig , EnvVars .DEFAULT_INSTANCE );
63
+ GCPResourceDetector testResource =
64
+ new GCPResourceDetector (mockMetadataConfig , EnvVars .DEFAULT_INSTANCE );
64
65
// If GCPMetadataConfig determines that its not running on GCP, then attributes should be empty
65
66
assertThat (testResource .getAttributes ()).isEmpty ();
66
67
}
@@ -72,7 +73,8 @@ public void testGCPComputeResourceNonGCPEndpoint() {
72
73
stubFor (
73
74
get (urlEqualTo ("/project/project-id" ))
74
75
.willReturn (aResponse ().withBody ("nonGCPendpointTest" )));
75
- GCPResource testResource = new GCPResource (metadataConfig , new EnvVarMock (envVars ));
76
+ GCPResourceDetector testResource =
77
+ new GCPResourceDetector (metadataConfig , new EnvVarMock (envVars ));
76
78
assertThat (testResource .getAttributes ()).isEmpty ();
77
79
}
78
80
@@ -85,7 +87,8 @@ public void testGCEResourceWithGCEAttributesSucceeds() {
85
87
stubEndpoint ("/instance/name" , "GCE-instance-name" );
86
88
stubEndpoint ("/instance/machine-type" , "GCE-instance-type" );
87
89
88
- final GCPResource testResource = new GCPResource (metadataConfig , new EnvVarMock (envVars ));
90
+ final GCPResourceDetector testResource =
91
+ new GCPResourceDetector (metadataConfig , new EnvVarMock (envVars ));
89
92
assertThat (testResource .getAttributes ())
90
93
.hasSize (8 )
91
94
.containsEntry (
@@ -118,7 +121,8 @@ public void testGKEResourceWithGKEAttributesSucceedsLocationZone() {
118
121
stubEndpoint ("/instance/attributes/cluster-name" , "GKE-cluster-name" );
119
122
stubEndpoint ("/instance/attributes/cluster-location" , "country-region-zone" );
120
123
121
- GCPResource testResource = new GCPResource (metadataConfig , new EnvVarMock (envVars ));
124
+ GCPResourceDetector testResource =
125
+ new GCPResourceDetector (metadataConfig , new EnvVarMock (envVars ));
122
126
assertThat (testResource .getAttributes ())
123
127
.hasSize (8 )
124
128
.containsEntry (ResourceAttributes .CLOUD_PROVIDER , "gcp" )
@@ -147,7 +151,8 @@ public void testGKEResourceWithGKEAttributesSucceedsLocationRegion() {
147
151
stubEndpoint ("/instance/attributes/cluster-name" , "GKE-cluster-name" );
148
152
stubEndpoint ("/instance/attributes/cluster-location" , "country-region" );
149
153
150
- GCPResource testResource = new GCPResource (metadataConfig , new EnvVarMock (envVars ));
154
+ GCPResourceDetector testResource =
155
+ new GCPResourceDetector (metadataConfig , new EnvVarMock (envVars ));
151
156
assertThat (testResource .getAttributes ())
152
157
.hasSize (8 )
153
158
.containsEntry (ResourceAttributes .CLOUD_PROVIDER , "gcp" )
@@ -172,7 +177,8 @@ public void testGCFResourceWithCloudFunctionAttributesSucceeds() {
172
177
stubEndpoint ("/instance/zone" , "country-region-zone" );
173
178
stubEndpoint ("/instance/id" , "GCF-instance-id" );
174
179
175
- GCPResource testResource = new GCPResource (metadataConfig , new EnvVarMock (envVars ));
180
+ GCPResourceDetector testResource =
181
+ new GCPResourceDetector (metadataConfig , new EnvVarMock (envVars ));
176
182
assertThat (testResource .getAttributes ())
177
183
.hasSize (7 )
178
184
.containsEntry (
@@ -200,7 +206,8 @@ public void testGAEResourceWithAppEngineAttributesSucceedsInFlex() {
200
206
stubEndpoint ("/instance/region" , "country-region1" );
201
207
stubEndpoint ("/instance/id" , "GAE-instance-id" );
202
208
203
- GCPResource testResource = new GCPResource (metadataConfig , new EnvVarMock (envVars ));
209
+ GCPResourceDetector testResource =
210
+ new GCPResourceDetector (metadataConfig , new EnvVarMock (envVars ));
204
211
assertThat (testResource .getAttributes ())
205
212
.hasSize (7 )
206
213
.containsEntry (
@@ -229,7 +236,8 @@ public void testGAEResourceWithAppEngineAttributesSucceedsInStandard() {
229
236
230
237
Map <String , String > updatedEnvVars = new HashMap <>(envVars );
231
238
updatedEnvVars .put ("GAE_ENV" , "standard" );
232
- GCPResource testResource = new GCPResource (metadataConfig , new EnvVarMock (updatedEnvVars ));
239
+ GCPResourceDetector testResource =
240
+ new GCPResourceDetector (metadataConfig , new EnvVarMock (updatedEnvVars ));
233
241
assertThat (testResource .getAttributes ())
234
242
.hasSize (7 )
235
243
.containsEntry (
0 commit comments