@@ -678,6 +678,97 @@ func TestUpsertPatchAsset(t *testing.T) {
678678
679679 },
680680 },
681+ {
682+ Description : "without explicit overwrite_lineage, should upsert asset without lineage" ,
683+ Setup : func (ctx context.Context , as * mocks.AssetService ) {
684+ patchedAsset := asset.Asset {
685+ URN : "test dagger" ,
686+ Type : asset .TypeTable ,
687+ Name : "new-name" ,
688+ Service : "kafka" ,
689+ UpdatedBy : user.User {ID : userID },
690+ Data : map [string ]interface {}{},
691+ Owners : []user.User {{ID : "id" , UUID : "" , Email : "email@email.com" , Provider : "provider" }},
692+ }
693+
694+ assetWithID := patchedAsset
695+ assetWithID .ID = assetID
696+
697+ as .EXPECT ().GetAssetByID (ctx , "test dagger" ).Return (currentAsset , nil )
698+ as .EXPECT ().UpsertAssetWithoutLineage (ctx , & patchedAsset ).
699+ Return (assetWithID .ID , nil ).
700+ Run (func (ctx context.Context , ast * asset.Asset ) {
701+ patchedAsset .ID = assetWithID .ID
702+ })
703+ },
704+ Request : & compassv1beta1.UpsertPatchAssetRequest {
705+ Asset : & compassv1beta1.UpsertPatchAssetRequest_Asset {
706+ Urn : "test dagger" ,
707+ Type : "table" ,
708+ Name : wrapperspb .String ("new-name" ),
709+ Service : "kafka" ,
710+ Data : & structpb.Struct {},
711+ Owners : []* compassv1beta1.User {{Id : "id" , Uuid : "" , Email : "email@email.com" , Provider : "provider" }},
712+ },
713+ },
714+ ExpectStatus : codes .OK ,
715+ PostCheck : func (resp * compassv1beta1.UpsertPatchAssetResponse ) error {
716+ expected := & compassv1beta1.UpsertPatchAssetResponse {
717+ Id : assetID ,
718+ }
719+ if diff := cmp .Diff (resp , expected , protocmp .Transform ()); diff != "" {
720+ return fmt .Errorf ("expected response to be %+v, was %+v" , expected , resp )
721+ }
722+ return nil
723+
724+ },
725+ },
726+ {
727+ Description : "with explicit overwrite_lineage, should upsert asset when lineage is not in the request" ,
728+ Setup : func (ctx context.Context , as * mocks.AssetService ) {
729+ patchedAsset := asset.Asset {
730+ URN : "test dagger" ,
731+ Type : asset .TypeTable ,
732+ Name : "new-name" ,
733+ Service : "kafka" ,
734+ UpdatedBy : user.User {ID : userID },
735+ Data : map [string ]interface {}{},
736+ Owners : []user.User {{ID : "id" , UUID : "" , Email : "email@email.com" , Provider : "provider" }},
737+ }
738+
739+ assetWithID := patchedAsset
740+ assetWithID .ID = assetID
741+
742+ as .EXPECT ().GetAssetByID (ctx , "test dagger" ).Return (currentAsset , nil )
743+ as .EXPECT ().UpsertAsset (ctx , & patchedAsset , []string {}, []string {}).
744+ Return (assetWithID .ID , nil ).
745+ Run (func (ctx context.Context , ast * asset.Asset , _ , _ []string ) {
746+ patchedAsset .ID = assetWithID .ID
747+ })
748+ },
749+ Request : & compassv1beta1.UpsertPatchAssetRequest {
750+ Asset : & compassv1beta1.UpsertPatchAssetRequest_Asset {
751+ Urn : "test dagger" ,
752+ Type : "table" ,
753+ Name : wrapperspb .String ("new-name" ),
754+ Service : "kafka" ,
755+ Data : & structpb.Struct {},
756+ Owners : []* compassv1beta1.User {{Id : "id" , Uuid : "" , Email : "email@email.com" , Provider : "provider" }},
757+ },
758+ OverwriteLineage : true ,
759+ },
760+ ExpectStatus : codes .OK ,
761+ PostCheck : func (resp * compassv1beta1.UpsertPatchAssetResponse ) error {
762+ expected := & compassv1beta1.UpsertPatchAssetResponse {
763+ Id : assetID ,
764+ }
765+ if diff := cmp .Diff (resp , expected , protocmp .Transform ()); diff != "" {
766+ return fmt .Errorf ("expected response to be %+v, was %+v" , expected , resp )
767+ }
768+ return nil
769+
770+ },
771+ },
681772 }
682773 for _ , tc := range testCases {
683774 t .Run (tc .Description , func (t * testing.T ) {
0 commit comments