@@ -20,6 +20,7 @@ import {
2020 HEADER_NAME ,
2121 HEADER_VALUE ,
2222 HOST_ADDRESS ,
23+ SECONDARY_HOST_ADDRESS ,
2324} from 'gcp-metadata' ;
2425import * as nock from 'nock' ;
2526import * as resource from '../src' ;
@@ -164,7 +165,11 @@ describe('detectResource', () => {
164165 . reply ( 200 , ( ) => 'project/zone/my-zone' , HEADERS )
165166 . get ( INSTANCE_ID_PATH )
166167 . reply ( 200 , ( ) => 4520031799277581759 , HEADERS ) ;
168+ const scope1 = nock ( SECONDARY_HOST_ADDRESS )
169+ . get ( INSTANCE_PATH )
170+ . reply ( 200 , { } , HEADERS ) ;
167171 const { type, labels } = await resource . detectResource ( ) ;
172+ scope1 . done ( ) ;
168173 scope . done ( ) ;
169174
170175 assert . deepStrictEqual ( type , resource . GCP_GCE_INSTANCE_TYPE ) ;
@@ -177,7 +182,6 @@ describe('detectResource', () => {
177182 it ( 'should retry if the initial request fails' , async ( ) => {
178183 const scope = nock ( HOST_ADDRESS )
179184 . get ( INSTANCE_PATH )
180- . times ( 2 )
181185 . reply ( 500 )
182186 . get ( INSTANCE_PATH )
183187 . reply ( 200 , { } , HEADERS )
@@ -187,7 +191,11 @@ describe('detectResource', () => {
187191 . reply ( 200 , ( ) => 'project/zone/my-zone' , HEADERS )
188192 . get ( INSTANCE_ID_PATH )
189193 . reply ( 200 , ( ) => 4520031799277581759 , HEADERS ) ;
194+ const secondaryScope = nock ( SECONDARY_HOST_ADDRESS )
195+ . get ( INSTANCE_PATH )
196+ . reply ( 200 , { } , HEADERS ) ;
190197 const { type, labels } = await resource . detectResource ( ) ;
198+ secondaryScope . done ( ) ;
191199 scope . done ( ) ;
192200
193201 assert . deepStrictEqual ( type , resource . GCP_GCE_INSTANCE_TYPE ) ;
@@ -207,7 +215,11 @@ describe('detectResource', () => {
207215 . reply ( 413 )
208216 . get ( INSTANCE_ID_PATH )
209217 . reply ( 400 , undefined , HEADERS ) ;
218+ const secondaryScope = nock ( SECONDARY_HOST_ADDRESS )
219+ . get ( INSTANCE_PATH )
220+ . reply ( 200 , { } , HEADERS ) ;
210221 const { type, labels } = await resource . detectResource ( ) ;
222+ secondaryScope . done ( ) ;
211223 scope . done ( ) ;
212224
213225 assert . deepStrictEqual ( type , resource . GCP_GCE_INSTANCE_TYPE ) ;
@@ -226,7 +238,6 @@ describe('detectResource', () => {
226238 process . env . OC_RESOURCE_TYPE = 'global' ;
227239 process . env . OC_RESOURCE_LABELS = 'cloud.zone=zone1,user=user1,version=1.0' ;
228240 CoreResource . setup ( ) ;
229-
230241 const scope = nock ( HOST_ADDRESS )
231242 . get ( INSTANCE_PATH )
232243 . reply ( 200 , { } , HEADERS )
@@ -236,7 +247,11 @@ describe('detectResource', () => {
236247 . reply ( 200 , ( ) => 'project/zone/my-zone' , HEADERS )
237248 . get ( INSTANCE_ID_PATH )
238249 . reply ( 200 , ( ) => 4520031799277581759 , HEADERS ) ;
250+ const secondaryScope = nock ( SECONDARY_HOST_ADDRESS )
251+ . get ( INSTANCE_PATH )
252+ . reply ( 200 , { } , HEADERS ) ;
239253 const { type, labels } = await resource . detectResource ( ) ;
254+ secondaryScope . done ( ) ;
240255 scope . done ( ) ;
241256
242257 assert . deepStrictEqual ( type , 'global' ) ;
0 commit comments