9
9
10
10
"github.com/googleapis/google-cloud-go-testing/bigquery/bqiface"
11
11
"github.com/goto/optimus/sdk/plugin"
12
+ "github.com/hashicorp/go-hclog"
12
13
"github.com/stretchr/testify/assert"
13
14
"github.com/stretchr/testify/mock"
14
15
@@ -33,8 +34,8 @@ type extractorFactoryMock struct {
33
34
mock.Mock
34
35
}
35
36
36
- func (e * extractorFactoryMock ) New (client bqiface.Client ) (UpstreamExtractor , error ) {
37
- args := e .Called (client )
37
+ func (e * extractorFactoryMock ) New (client bqiface.Client , logger hclog. Logger ) (UpstreamExtractor , error ) {
38
+ args := e .Called (client , logger )
38
39
39
40
r1 , ok := args .Get (0 ).(UpstreamExtractor )
40
41
if ! ok {
@@ -48,10 +49,10 @@ type extractorMock struct {
48
49
mock.Mock
49
50
}
50
51
51
- func (e * extractorMock ) ExtractUpstreams (ctx context.Context , query string , resourcesToIgnore []upstream.Resource ) ([]* upstream.Upstream , error ) {
52
+ func (e * extractorMock ) ExtractUpstreams (ctx context.Context , query string , resourcesToIgnore []upstream.Resource ) ([]upstream.Resource , error ) {
52
53
args := e .Called (ctx , query , resourcesToIgnore )
53
54
54
- r1 , ok := args .Get (0 ).([]* upstream.Upstream )
55
+ r1 , ok := args .Get (0 ).([]upstream.Resource )
55
56
if ! ok {
56
57
return nil , args .Error (1 )
57
58
}
@@ -61,6 +62,7 @@ func (e *extractorMock) ExtractUpstreams(ctx context.Context, query string, reso
61
62
62
63
func TestBQ2BQ (t * testing.T ) {
63
64
ctx := context .Background ()
65
+ logger := hclog .NewNullLogger ()
64
66
65
67
t .Run ("GetName" , func (t * testing.T ) {
66
68
t .Run ("should return name bq2bq" , func (t * testing.T ) {
@@ -263,22 +265,21 @@ Select * from table where ts > "2021-01-16T00:00:00Z"`
263
265
264
266
extractor := new (extractorMock )
265
267
extractor .On ("ExtractUpstreams" , mock .Anything , query , []upstream.Resource {destination }).
266
- Return ([]* upstream.Upstream {
268
+ Return ([]upstream.Resource {
267
269
{
268
- Resource : upstream.Resource {
269
- Project : "proj" ,
270
- Dataset : "dataset" ,
271
- Name : "table1" ,
272
- },
270
+ Project : "proj" ,
271
+ Dataset : "dataset" ,
272
+ Name : "table1" ,
273
273
},
274
274
}, nil )
275
275
276
276
extractorFac := new (extractorFactoryMock )
277
- extractorFac .On ("New" , client ).Return (extractor , nil )
277
+ extractorFac .On ("New" , client , logger ).Return (extractor , nil )
278
278
279
279
b := & BQ2BQ {
280
280
ClientFac : bqClientFac ,
281
281
ExtractorFac : extractorFac ,
282
+ logger : logger ,
282
283
}
283
284
got , err := b .GenerateDependencies (ctx , data )
284
285
if err != nil {
@@ -335,45 +336,26 @@ Select * from table where ts > "2021-01-16T00:00:00Z"`
335
336
336
337
extractor := new (extractorMock )
337
338
extractor .On ("ExtractUpstreams" , mock .Anything , query , []upstream.Resource {destination }).
338
- Return ([]* upstream.Upstream {
339
- {
340
- Resource : upstream.Resource {
341
- Project : "proj" ,
342
- Dataset : "dataset" ,
343
- Name : "table1" ,
344
- },
345
- Upstreams : []* upstream.Upstream {
346
- {
347
- Resource : upstream.Resource {
348
- Project : "proj" ,
349
- Dataset : "dataset" ,
350
- Name : "table2" ,
351
- },
352
- },
353
- },
354
- },
355
- {
356
- Resource : upstream.Resource {
357
- Project : "proj" ,
358
- Dataset : "dataset" ,
359
- Name : "table2" ,
360
- },
361
- },
362
- {
363
- Resource : upstream.Resource {
364
- Project : "proj" ,
365
- Dataset : "dataset" ,
366
- Name : "table1" ,
367
- },
339
+ Return ([]upstream.Resource {
340
+ {
341
+ Project : "proj" ,
342
+ Dataset : "dataset" ,
343
+ Name : "table1" ,
344
+ },
345
+ {
346
+ Project : "proj" ,
347
+ Dataset : "dataset" ,
348
+ Name : "table2" ,
368
349
},
369
350
}, nil )
370
351
371
352
extractorFac := new (extractorFactoryMock )
372
- extractorFac .On ("New" , client ).Return (extractor , nil )
353
+ extractorFac .On ("New" , client , logger ).Return (extractor , nil )
373
354
374
355
b := & BQ2BQ {
375
356
ClientFac : bqClientFac ,
376
357
ExtractorFac : extractorFac ,
358
+ logger : logger ,
377
359
}
378
360
got , err := b .GenerateDependencies (ctx , data )
379
361
if err != nil {
@@ -430,14 +412,15 @@ Select * from table where ts > "2021-01-16T00:00:00Z"`
430
412
431
413
extractor := new (extractorMock )
432
414
extractor .On ("ExtractUpstreams" , mock .Anything , query , []upstream.Resource {destination }).
433
- Return ([]* upstream.Upstream {}, nil )
415
+ Return ([]upstream.Resource {}, nil )
434
416
435
417
extractorFac := new (extractorFactoryMock )
436
- extractorFac .On ("New" , client ).Return (extractor , nil )
418
+ extractorFac .On ("New" , client , logger ).Return (extractor , nil )
437
419
438
420
b := & BQ2BQ {
439
421
ClientFac : bqClientFac ,
440
422
ExtractorFac : extractorFac ,
423
+ logger : logger ,
441
424
}
442
425
got , err := b .GenerateDependencies (ctx , data )
443
426
if err != nil {
@@ -494,22 +477,21 @@ Select * from table where ts > "2021-01-16T00:00:00Z"`
494
477
495
478
extractor := new (extractorMock )
496
479
extractor .On ("ExtractUpstreams" , mock .Anything , query , []upstream.Resource {destination }).
497
- Return ([]* upstream.Upstream {
480
+ Return ([]upstream.Resource {
498
481
{
499
- Resource : upstream.Resource {
500
- Project : "proj" ,
501
- Dataset : "dataset" ,
502
- Name : "table1" ,
503
- },
482
+ Project : "proj" ,
483
+ Dataset : "dataset" ,
484
+ Name : "table1" ,
504
485
},
505
486
}, nil )
506
487
507
488
extractorFac := new (extractorFactoryMock )
508
- extractorFac .On ("New" , client ).Return (extractor , nil )
489
+ extractorFac .On ("New" , client , logger ).Return (extractor , nil )
509
490
510
491
b := & BQ2BQ {
511
492
ClientFac : bqClientFac ,
512
493
ExtractorFac : extractorFac ,
494
+ logger : logger ,
513
495
}
514
496
got , err := b .GenerateDependencies (ctx , data )
515
497
if err != nil {
@@ -566,22 +548,21 @@ Select * from table where ts > "2021-01-16T00:00:00Z"`
566
548
567
549
extractor := new (extractorMock )
568
550
extractor .On ("ExtractUpstreams" , mock .Anything , query , []upstream.Resource {destination }).
569
- Return ([]* upstream.Upstream {
551
+ Return ([]upstream.Resource {
570
552
{
571
- Resource : upstream.Resource {
572
- Project : "proj" ,
573
- Dataset : "dataset" ,
574
- Name : "table1" ,
575
- },
553
+ Project : "proj" ,
554
+ Dataset : "dataset" ,
555
+ Name : "table1" ,
576
556
},
577
557
}, nil )
578
558
579
559
extractorFac := new (extractorFactoryMock )
580
- extractorFac .On ("New" , client ).Return (extractor , nil )
560
+ extractorFac .On ("New" , client , logger ).Return (extractor , nil )
581
561
582
562
b := & BQ2BQ {
583
563
ClientFac : bqClientFac ,
584
564
ExtractorFac : extractorFac ,
565
+ logger : logger ,
585
566
}
586
567
got , err := b .GenerateDependencies (ctx , data )
587
568
if err != nil {
0 commit comments