@@ -194,7 +194,7 @@ func TestService_UpsertAsset(t *testing.T) {
194
194
Description : `should return error if asset repository upsert return error` ,
195
195
Asset : sampleAsset ,
196
196
Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
197
- ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (asset. Asset {} , errors .New ("unknown error" ))
197
+ ar .EXPECT ().Upsert (ctx , sampleAsset ).Return ("" , errors .New ("unknown error" ))
198
198
},
199
199
Err : errors .New ("unknown error" ),
200
200
ReturnedID : "" ,
@@ -203,7 +203,7 @@ func TestService_UpsertAsset(t *testing.T) {
203
203
Description : `should return error if discovery repository upsert return error` ,
204
204
Asset : sampleAsset ,
205
205
Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
206
- ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (* sampleAsset , nil )
206
+ ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (sampleAsset . ID , nil )
207
207
dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (errors .New ("unknown error" ))
208
208
},
209
209
Err : errors .New ("unknown error" ),
@@ -215,7 +215,7 @@ func TestService_UpsertAsset(t *testing.T) {
215
215
Upstreams : sampleNodes1 ,
216
216
Downstreams : sampleNodes2 ,
217
217
Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
218
- ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (* sampleAsset , nil )
218
+ ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (sampleAsset . ID , nil )
219
219
dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (nil )
220
220
lr .EXPECT ().Upsert (ctx , sampleAsset .URN , sampleNodes1 , sampleNodes2 ).Return (errors .New ("unknown error" ))
221
221
},
@@ -228,7 +228,7 @@ func TestService_UpsertAsset(t *testing.T) {
228
228
Upstreams : sampleNodes1 ,
229
229
Downstreams : sampleNodes2 ,
230
230
Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
231
- ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (* sampleAsset , nil )
231
+ ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (sampleAsset . ID , nil )
232
232
dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (nil )
233
233
lr .EXPECT ().Upsert (ctx , sampleAsset .URN , sampleNodes1 , sampleNodes2 ).Return (nil )
234
234
},
@@ -279,15 +279,15 @@ func TestService_UpsertAssetWithoutLineage(t *testing.T) {
279
279
Description : `should return error if asset repository upsert return error` ,
280
280
Asset : sampleAsset ,
281
281
Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository ) {
282
- ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (asset. Asset {} , errors .New ("unknown error" ))
282
+ ar .EXPECT ().Upsert (ctx , sampleAsset ).Return ("" , errors .New ("unknown error" ))
283
283
},
284
284
Err : errors .New ("unknown error" ),
285
285
},
286
286
{
287
287
Description : `should return error if discovery repository upsert return error` ,
288
288
Asset : sampleAsset ,
289
289
Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository ) {
290
- ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (* sampleAsset , nil )
290
+ ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (sampleAsset . ID , nil )
291
291
dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (errors .New ("unknown error" ))
292
292
},
293
293
Err : errors .New ("unknown error" ),
@@ -296,7 +296,7 @@ func TestService_UpsertAssetWithoutLineage(t *testing.T) {
296
296
Description : `should return no error if all repositories upsert return no error` ,
297
297
Asset : sampleAsset ,
298
298
Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository ) {
299
- ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (* sampleAsset , nil )
299
+ ar .EXPECT ().Upsert (ctx , sampleAsset ).Return (sampleAsset . ID , nil )
300
300
dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (nil )
301
301
},
302
302
ReturnedID : sampleAsset .ID ,
@@ -331,6 +331,164 @@ func TestService_UpsertAssetWithoutLineage(t *testing.T) {
331
331
}
332
332
}
333
333
334
+ func TestService_UpsertPatchAsset (t * testing.T ) {
335
+ sampleAsset := & asset.Asset {ID : "some-id" , URN : "some-urn" , Type : asset .Type ("dashboard" ), Service : "some-service" }
336
+ sampleNodes1 := []string {"1-urn-1" , "1-urn-2" }
337
+ sampleNodes2 := []string {"2-urn-1" , "2-urn-2" }
338
+ type testCase struct {
339
+ Description string
340
+ Asset * asset.Asset
341
+ Upstreams []string
342
+ Downstreams []string
343
+ Err error
344
+ ReturnedID string
345
+ Setup func (context.Context , * mocks.AssetRepository , * mocks.DiscoveryRepository , * mocks.LineageRepository )
346
+ }
347
+
348
+ testCases := []testCase {
349
+ {
350
+ Description : `should return error if asset repository upsert return error` ,
351
+ Asset : sampleAsset ,
352
+ Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
353
+ ar .EXPECT ().UpsertPatch (ctx , sampleAsset , mock .Anything ).Return ("" , errors .New ("unknown error" ))
354
+ },
355
+ Err : errors .New ("unknown error" ),
356
+ ReturnedID : "" ,
357
+ },
358
+ {
359
+ Description : `should return error if discovery repository upsert return error` ,
360
+ Asset : sampleAsset ,
361
+ Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
362
+ ar .EXPECT ().UpsertPatch (ctx , sampleAsset , mock .Anything ).Return (sampleAsset .ID , nil )
363
+ dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (errors .New ("unknown error" ))
364
+ },
365
+ Err : errors .New ("unknown error" ),
366
+ ReturnedID : sampleAsset .ID ,
367
+ },
368
+ {
369
+ Description : `should return error if lineage repository upsert return error` ,
370
+ Asset : sampleAsset ,
371
+ Upstreams : sampleNodes1 ,
372
+ Downstreams : sampleNodes2 ,
373
+ Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
374
+ ar .EXPECT ().UpsertPatch (ctx , sampleAsset , mock .Anything ).Return (sampleAsset .ID , nil )
375
+ dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (nil )
376
+ lr .EXPECT ().Upsert (ctx , sampleAsset .URN , sampleNodes1 , sampleNodes2 ).Return (errors .New ("unknown error" ))
377
+ },
378
+ Err : errors .New ("unknown error" ),
379
+ ReturnedID : sampleAsset .ID ,
380
+ },
381
+ {
382
+ Description : `should return no error if all repositories upsert return no error` ,
383
+ Asset : sampleAsset ,
384
+ Upstreams : sampleNodes1 ,
385
+ Downstreams : sampleNodes2 ,
386
+ Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository , lr * mocks.LineageRepository ) {
387
+ ar .EXPECT ().UpsertPatch (ctx , sampleAsset , mock .Anything ).Return (sampleAsset .ID , nil )
388
+ dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (nil )
389
+ lr .EXPECT ().Upsert (ctx , sampleAsset .URN , sampleNodes1 , sampleNodes2 ).Return (nil )
390
+ },
391
+ Err : nil ,
392
+ ReturnedID : sampleAsset .ID ,
393
+ },
394
+ }
395
+ for _ , tc := range testCases {
396
+ t .Run (tc .Description , func (t * testing.T ) {
397
+ ctx := context .Background ()
398
+
399
+ assetRepo := mocks .NewAssetRepository (t )
400
+ discoveryRepo := mocks .NewDiscoveryRepository (t )
401
+ lineageRepo := mocks .NewLineageRepository (t )
402
+ if tc .Setup != nil {
403
+ tc .Setup (ctx , assetRepo , discoveryRepo , lineageRepo )
404
+ }
405
+
406
+ svc , cancel := asset .NewService (asset.ServiceDeps {
407
+ AssetRepo : assetRepo ,
408
+ DiscoveryRepo : discoveryRepo ,
409
+ LineageRepo : lineageRepo ,
410
+ Worker : workermanager .NewInSituWorker (workermanager.Deps {DiscoveryRepo : discoveryRepo }),
411
+ })
412
+ defer cancel ()
413
+
414
+ patchData := make (map [string ]interface {})
415
+ rid , err := svc .UpsertPatchAsset (ctx , tc .Asset , tc .Upstreams , tc .Downstreams , patchData )
416
+ if tc .Err != nil {
417
+ assert .ErrorContains (t , err , tc .Err .Error ())
418
+ return
419
+ }
420
+ assert .NoError (t , err )
421
+ assert .Equal (t , tc .ReturnedID , rid )
422
+ })
423
+ }
424
+ }
425
+
426
+ func TestService_UpsertPatchAssetWithoutLineage (t * testing.T ) {
427
+ sampleAsset := & asset.Asset {ID : "some-id" , URN : "some-urn" , Type : asset .Type ("dashboard" ), Service : "some-service" }
428
+ testCases := []struct {
429
+ Description string
430
+ Asset * asset.Asset
431
+ Err error
432
+ ReturnedID string
433
+ Setup func (context.Context , * mocks.AssetRepository , * mocks.DiscoveryRepository )
434
+ }{
435
+ {
436
+ Description : `should return error if asset repository upsert return error` ,
437
+ Asset : sampleAsset ,
438
+ Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository ) {
439
+ ar .EXPECT ().UpsertPatch (ctx , sampleAsset , mock .Anything ).Return ("" , errors .New ("unknown error" ))
440
+ },
441
+ Err : errors .New ("unknown error" ),
442
+ },
443
+ {
444
+ Description : `should return error if discovery repository upsert return error` ,
445
+ Asset : sampleAsset ,
446
+ Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository ) {
447
+ ar .EXPECT ().UpsertPatch (ctx , sampleAsset , mock .Anything ).Return (sampleAsset .ID , nil )
448
+ dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (errors .New ("unknown error" ))
449
+ },
450
+ Err : errors .New ("unknown error" ),
451
+ },
452
+ {
453
+ Description : `should return no error if all repositories upsert return no error` ,
454
+ Asset : sampleAsset ,
455
+ Setup : func (ctx context.Context , ar * mocks.AssetRepository , dr * mocks.DiscoveryRepository ) {
456
+ ar .EXPECT ().UpsertPatch (ctx , sampleAsset , mock .Anything ).Return (sampleAsset .ID , nil )
457
+ dr .EXPECT ().Upsert (ctx , mock .AnythingOfType ("asset.Asset" )).Return (nil )
458
+ },
459
+ ReturnedID : sampleAsset .ID ,
460
+ },
461
+ }
462
+ for _ , tc := range testCases {
463
+ t .Run (tc .Description , func (t * testing.T ) {
464
+ ctx := context .Background ()
465
+
466
+ assetRepo := mocks .NewAssetRepository (t )
467
+ discoveryRepo := mocks .NewDiscoveryRepository (t )
468
+ if tc .Setup != nil {
469
+ tc .Setup (ctx , assetRepo , discoveryRepo )
470
+ }
471
+
472
+ svc , cancel := asset .NewService (asset.ServiceDeps {
473
+ AssetRepo : assetRepo ,
474
+ DiscoveryRepo : discoveryRepo ,
475
+ LineageRepo : mocks .NewLineageRepository (t ),
476
+ Worker : workermanager .NewInSituWorker (workermanager.Deps {DiscoveryRepo : discoveryRepo }),
477
+ })
478
+ defer cancel ()
479
+
480
+ patchData := make (map [string ]interface {})
481
+ rid , err := svc .UpsertPatchAssetWithoutLineage (ctx , tc .Asset , patchData )
482
+ if tc .Err != nil {
483
+ assert .ErrorContains (t , err , tc .Err .Error ())
484
+ return
485
+ }
486
+ assert .NoError (t , err )
487
+ assert .Equal (t , tc .ReturnedID , rid )
488
+ })
489
+ }
490
+ }
491
+
334
492
func TestService_DeleteAsset (t * testing.T ) {
335
493
assetID := "d9351e2e-a6b2-4c5d-af68-b95432e30203"
336
494
urn := "my-test-urn"
0 commit comments