@@ -296,6 +296,119 @@ func TestAliasedAddressSpaceGoogleCurrent(t *testing.T) {
296
296
}
297
297
}
298
298
299
+ func TestConfigDrivenAliasedAddressSpaceGoogleCurrent (t * testing.T ) {
300
+ registryLocalPath := "./testdata/registry/basic"
301
+ googleProviderPath := "testdata/registry/basic/src/googleapis.com/v0.1.2/provider.yaml"
302
+ // expectedErrorCount := 282
303
+ analyzerFactory := discovery .NewSimpleSQLiteAnalyzerFactory (registryLocalPath , dto.RuntimeCtx {})
304
+ staticAnalyzer , analyzerErr := analyzerFactory .CreateProviderServiceLevelStaticAnalyzer (
305
+ googleProviderPath ,
306
+ "compute" ,
307
+ )
308
+ if analyzerErr != nil {
309
+ t .Fatalf ("Failed to create static analyzer: %v" , analyzerErr )
310
+ }
311
+ err := staticAnalyzer .Analyze ()
312
+ if err != nil {
313
+ t .Fatalf ("Static analysis failed: %v" , err )
314
+ }
315
+ staticAnalyzer .GetResources ()
316
+ errorSlice := staticAnalyzer .GetErrors ()
317
+ for _ , err := range errorSlice {
318
+ t .Logf ("Static analysis error: %v" , err )
319
+ }
320
+ // these are shallow
321
+ resources := staticAnalyzer .GetResources ()
322
+ t .Logf ("Discovered %d resources" , len (resources ))
323
+ if len (resources ) == 0 {
324
+ t .Fatalf ("Static analysis failed: expected non-zero resources but got %d" , len (resources ))
325
+ }
326
+ svcFrags := staticAnalyzer .GetServiceFragments ()
327
+ svc , hasSvc := svcFrags ["instanceGroups" ]
328
+ if ! hasSvc {
329
+ t .Fatalf ("Static analysis failed: expected 'compute' service to exist" )
330
+ }
331
+ rsc , hasRsc := resources ["instanceGroups" ]
332
+ if ! hasRsc {
333
+ t .Fatalf ("Static analysis failed: expected 'instanceGroups' resource to exist on service" )
334
+ }
335
+ if rsc == nil {
336
+ t .Fatalf ("Static analysis failed: expected non-nil 'instanceGroups' resource to exist" )
337
+ }
338
+ selectInstanceGroupMethod , selectInstanceGroupMethodErr := rsc .FindMethod ("aggregatedList" )
339
+ if selectInstanceGroupMethodErr != nil {
340
+ t .Fatalf ("Static analysis failed: expected 'select' method to exist on 'instanceGroups' resource" )
341
+ }
342
+ prov , hasProv := rsc .GetProvider ()
343
+ if ! hasProv {
344
+ t .Fatalf ("Static analysis failed: expected provider to exist on 'images' resource" )
345
+ }
346
+
347
+ addressSpaceAnalyzer := radix_tree_address_space .NewAddressSpaceAnalyzer (
348
+ radix_tree_address_space .NewAddressSpaceGrammar (),
349
+ prov ,
350
+ svc ,
351
+ rsc ,
352
+ selectInstanceGroupMethod ,
353
+ "$.items" ,
354
+ "$.items[*].instanceGroups[*].name" ,
355
+ )
356
+ err = addressSpaceAnalyzer .Analyze ()
357
+ if err != nil {
358
+ t .Fatalf ("Address space analysis failed: %v" , err )
359
+ }
360
+ addressSpace := addressSpaceAnalyzer .GetAddressSpace ()
361
+ if addressSpace == nil {
362
+ t .Fatalf ("Address space analysis failed: expected non-nil address space" )
363
+ }
364
+ simpleSelectSchema := addressSpace .GetSimpleSelectSchema ()
365
+ if simpleSelectSchema == nil {
366
+ t .Fatalf ("Address space analysis failed: expected non-nil simple select schema" )
367
+ }
368
+ unionSelectSchemas := addressSpace .GetUnionSelectSchemas ()
369
+ if len (unionSelectSchemas ) != 2 {
370
+ t .Fatalf ("Address space analysis failed: expected 2 union select schemas but got %d" , len (unionSelectSchemas ))
371
+ }
372
+ for k , v := range unionSelectSchemas {
373
+ t .Logf ("Union select schema key: %s, schema title: %s" , k , v .GetTitle ())
374
+ }
375
+ requestBody , requestBodyOk := addressSpace .DereferenceAddress ("request.body" )
376
+ if ! requestBodyOk {
377
+ t .Fatalf ("Address space analysis failed: expected to dereference 'request.body'" )
378
+ }
379
+ if requestBody != nil {
380
+ t .Fatalf ("Address space analysis failed: expected nil 'request.body'" )
381
+ }
382
+ responseBody , responseBodyOk := addressSpace .DereferenceAddress ("response.body" )
383
+ if ! responseBodyOk {
384
+ t .Fatalf ("Address space analysis failed: expected to dereference 'response.body'" )
385
+ }
386
+ if responseBody == nil {
387
+ t .Fatalf ("Address space analysis failed: expected non-nil 'response.body'" )
388
+ }
389
+ projectParam , projectParamOk := addressSpace .DereferenceAddress (".project" )
390
+ if ! projectParamOk {
391
+ t .Fatalf ("Address space analysis failed: expected to dereference '.project'" )
392
+ }
393
+ if projectParam == nil {
394
+ t .Fatalf ("Address space analysis failed: expected non-nil '.project'" )
395
+ }
396
+ mutateProjectErr := addressSpace .WriteToAddress (".project" , "my-test-project" )
397
+ if mutateProjectErr != nil {
398
+ t .Fatalf ("Address space analysis failed: expected to write to address '.project'" )
399
+ }
400
+ projectVal , projectValOk := addressSpace .ReadFromAddress (".project" )
401
+ if ! projectValOk {
402
+ t .Fatalf ("Address space analysis failed: expected to read from address '.project'" )
403
+ }
404
+ if projectVal == nil {
405
+ t .Fatalf ("Address space analysis failed: expected non-nil value from address '.project'" )
406
+ }
407
+ if projectVal != "my-test-project" {
408
+ t .Fatalf ("Address space analysis failed: expected 'my-test-project' from address '.project' but got '%v'" , projectVal )
409
+ }
410
+ }
411
+
299
412
func TestBasicAddressSpaceAWSCurrent (t * testing.T ) {
300
413
registryLocalPath := "./testdata/registry/basic"
301
414
googleProviderPath := "testdata/registry/basic/src/aws/v0.1.0/provider.yaml"
0 commit comments