-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dedupe owners in upsert/patch asset
- Loading branch information
1 parent
fa6266d
commit 14020c9
Showing
6 changed files
with
179 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,22 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/raystack/compass/core/namespace" | ||
"github.com/raystack/compass/pkg/grpc_interceptor" | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/raystack/compass/core/namespace" | ||
"github.com/raystack/compass/pkg/grpc_interceptor" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/uuid" | ||
"github.com/r3labs/diff/v2" | ||
"github.com/raystack/compass/core/asset" | ||
"github.com/raystack/compass/core/star" | ||
"github.com/raystack/compass/core/user" | ||
"github.com/raystack/compass/internal/server/v1beta1/mocks" | ||
compassv1beta1 "github.com/raystack/compass/proto/raystack/compass/v1beta1" | ||
"github.com/raystack/salt/log" | ||
"github.com/r3labs/diff/v2" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc/codes" | ||
|
@@ -364,8 +365,13 @@ func TestUpsertAsset(t *testing.T) { | |
Service: "kafka", | ||
Data: &structpb.Struct{}, | ||
Url: "https://sample-url.com", | ||
Owners: []*compassv1beta1.User{{Id: "id", Uuid: "", Email: "[email protected]", Provider: "provider"}}, | ||
}, | ||
Owners: []*compassv1beta1.User{ | ||
{Id: "id", Uuid: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}, | ||
// the following users should get de-duplicated. | ||
{Id: "id"}, | ||
{Uuid: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8"}, | ||
{Email: "[email protected]"}, | ||
}}, | ||
Upstreams: []*compassv1beta1.LineageNode{ | ||
{ | ||
Urn: "upstream-1", | ||
|
@@ -498,7 +504,7 @@ func TestUpsertAsset(t *testing.T) { | |
UpdatedBy: user.User{ID: userID}, | ||
Data: map[string]interface{}{}, | ||
URL: "https://sample-url.com", | ||
Owners: []user.User{{ID: "id", UUID: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []user.User{{ID: "id", UUID: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}}, | ||
} | ||
upstreams := []string{"upstream-1"} | ||
downstreams := []string{"downstream-1", "downstream-2"} | ||
|
@@ -576,7 +582,13 @@ func TestUpsertPatchAsset(t *testing.T) { | |
Service: "kafka", | ||
Data: &structpb.Struct{}, | ||
Url: "https://sample-url.com", | ||
Owners: []*compassv1beta1.User{{Id: "id", Uuid: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []*compassv1beta1.User{ | ||
{Id: "id", Uuid: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}, | ||
// the following users should get de-duplicated. | ||
{Id: "id"}, | ||
{Uuid: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8"}, | ||
{Email: "[email protected]"}, | ||
}, | ||
}, | ||
Upstreams: []*compassv1beta1.LineageNode{ | ||
{ | ||
|
@@ -606,7 +618,7 @@ func TestUpsertPatchAsset(t *testing.T) { | |
UpdatedBy: user.User{ID: userID}, | ||
Data: map[string]interface{}{}, | ||
URL: "https://sample-url-old.com", | ||
Owners: []user.User{{ID: "id", UUID: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []user.User{{ID: "id", UUID: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}}, | ||
} | ||
) | ||
ctx := user.NewContext(context.Background(), user.User{UUID: userUUID}) | ||
|
@@ -724,7 +736,7 @@ func TestUpsertPatchAsset(t *testing.T) { | |
UpdatedBy: user.User{ID: userID}, | ||
Data: map[string]interface{}{}, | ||
URL: "https://sample-url.com", | ||
Owners: []user.User{{ID: "id", UUID: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []user.User{{ID: "id", UUID: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}}, | ||
} | ||
upstreams := []string{"upstream-1"} | ||
downstreams := []string{"downstream-1", "downstream-2"} | ||
|
@@ -761,7 +773,7 @@ func TestUpsertPatchAsset(t *testing.T) { | |
UpdatedBy: user.User{ID: userID}, | ||
Data: map[string]interface{}{}, | ||
URL: "https://sample-url-old.com", | ||
Owners: []user.User{{ID: "id", UUID: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []user.User{{ID: "id", UUID: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}}, | ||
} | ||
|
||
assetWithID := patchedAsset | ||
|
@@ -781,7 +793,7 @@ func TestUpsertPatchAsset(t *testing.T) { | |
Name: wrapperspb.String("new-name"), | ||
Service: "kafka", | ||
Data: &structpb.Struct{}, | ||
Owners: []*compassv1beta1.User{{Id: "id", Uuid: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []*compassv1beta1.User{{Id: "id", Uuid: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}}, | ||
}, | ||
}, | ||
ExpectStatus: codes.OK, | ||
|
@@ -807,7 +819,7 @@ func TestUpsertPatchAsset(t *testing.T) { | |
UpdatedBy: user.User{ID: userID}, | ||
Data: map[string]interface{}{}, | ||
URL: "https://sample-url-old.com", | ||
Owners: []user.User{{ID: "id", UUID: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []user.User{{ID: "id", UUID: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}}, | ||
} | ||
|
||
assetWithID := patchedAsset | ||
|
@@ -827,7 +839,7 @@ func TestUpsertPatchAsset(t *testing.T) { | |
Name: wrapperspb.String("new-name"), | ||
Service: "kafka", | ||
Data: &structpb.Struct{}, | ||
Owners: []*compassv1beta1.User{{Id: "id", Uuid: "", Email: "[email protected]", Provider: "provider"}}, | ||
Owners: []*compassv1beta1.User{{Id: "id", Uuid: "1aecb8b3-23a9-4456-8ebd-3aafc746fff8", Email: "[email protected]", Provider: "provider"}}, | ||
}, | ||
OverwriteLineage: true, | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,12 @@ import ( | |
sq "github.com/Masterminds/squirrel" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/uuid" | ||
"github.com/ory/dockertest/v3" | ||
"github.com/r3labs/diff/v2" | ||
"github.com/raystack/compass/core/asset" | ||
"github.com/raystack/compass/core/user" | ||
"github.com/raystack/compass/internal/store/postgres" | ||
"github.com/raystack/salt/log" | ||
"github.com/ory/dockertest/v3" | ||
"github.com/r3labs/diff/v2" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
|
@@ -986,8 +986,10 @@ func (r *AssetRepositoryTestSuite) TestUpsert() { | |
Type: "table", | ||
Service: "bigquery", | ||
Owners: []user.User{ | ||
stripUserID(r.users[1]), | ||
r.users[1], | ||
{Email: r.users[2].Email}, | ||
{UUID: r.users[2].UUID}, // should get deduplicated by ID on fetch by UUID | ||
{ID: r.users[1].ID}, // should get deduplicated by ID | ||
}, | ||
UpdatedBy: r.users[0], | ||
} | ||
|
@@ -1000,7 +1002,7 @@ func (r *AssetRepositoryTestSuite) TestUpsert() { | |
actual, err := r.repository.GetByID(r.ctx, ast.ID) | ||
r.NoError(err) | ||
|
||
r.Len(actual.Owners, len(ast.Owners)) | ||
r.Len(actual.Owners, 2) | ||
r.Equal(r.users[1].ID, actual.Owners[0].ID) | ||
r.Equal(r.users[2].ID, actual.Owners[1].ID) | ||
}) | ||
|
@@ -1013,6 +1015,7 @@ func (r *AssetRepositoryTestSuite) TestUpsert() { | |
Owners: []user.User{ | ||
{Email: "[email protected]"}, | ||
{UUID: "108151e5-4c9f-4951-a8e1-6966b5aa2bb6"}, | ||
{Email: "[email protected]"}, // should get deduplicated by ID on fetch user by email | ||
}, | ||
UpdatedBy: r.users[0], | ||
} | ||
|
@@ -1024,7 +1027,7 @@ func (r *AssetRepositoryTestSuite) TestUpsert() { | |
actual, err := r.repository.GetByID(r.ctx, id) | ||
r.NoError(err) | ||
|
||
r.Len(actual.Owners, len(ast.Owners)) | ||
r.Len(actual.Owners, 2) | ||
r.Equal(ast.Owners[0].Email, actual.Owners[0].Email) | ||
r.Equal(ast.Owners[1].UUID, actual.Owners[1].UUID) | ||
}) | ||
|
Oops, something went wrong.