Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove read report function and add tests #283

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions authorization/authorization_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var _ = Describe("Authorized", func() {
},
},
}
policyTags := []string{"Tag1"}
policyTags := []string{"TagOne"}

resp, err := authorizationClient.IsAuthorized(
context.Background(),
Expand Down Expand Up @@ -962,19 +962,19 @@ var _ = Describe("Authorized", func() {
action: PointTo(MatchFields(IgnoreExtras, Fields{
"Resources": MatchAllElementsWithIndex(IndexIdentity, Elements{
"0": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset3),
"ExternalId": Equal(integration.Asset4),
})),
"1": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset4),
"ExternalId": Equal(integration.Asset3),
})),
"2": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset1),
})),
"3": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset5),
"ExternalId": Equal(integration.Asset2),
})),
"4": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset2),
"ExternalId": Equal(integration.Asset5),
})),
}),
})),
Expand Down Expand Up @@ -1197,10 +1197,10 @@ var _ = Describe("Authorized", func() {
action: PointTo(MatchFields(IgnoreExtras, Fields{
"Resources": MatchAllElementsWithIndex(IndexIdentity, Elements{
"0": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset3),
"ExternalId": Equal(integration.Asset4),
})),
"1": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset4),
"ExternalId": Equal(integration.Asset3),
})),
"2": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset1),
Expand Down Expand Up @@ -1308,10 +1308,10 @@ var _ = Describe("Authorized", func() {
action: PointTo(MatchFields(IgnoreExtras, Fields{
"Resources": MatchAllElementsWithIndex(IndexIdentity, Elements{
"0": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset3),
"ExternalId": Equal(integration.Asset4),
})),
"1": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset4),
"ExternalId": Equal(integration.Asset3),
})),
"2": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Asset1),
Expand Down Expand Up @@ -1447,13 +1447,13 @@ var _ = Describe("Authorized", func() {
action0: PointTo(MatchFields(IgnoreExtras, Fields{
"Subjects": MatchAllElementsWithIndex(IndexIdentity, Elements{
"0": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Subject2),
"ExternalId": Equal(integration.Subject1),
})),
"1": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Subject1),
"ExternalId": Equal(integration.Subject3),
})),
"2": PointTo(MatchFields(IgnoreExtras, Fields{
"ExternalId": Equal(integration.Subject3),
"ExternalId": Equal(integration.Subject2),
})),
}),
})),
Expand Down
190 changes: 190 additions & 0 deletions config/config_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ var _ = Describe("Configuration", func() {
respDelAS, err := configClient.DeleteApplicationSpace(context.Background(), reqDelAS)
Expect(err).To(Succeed())
Expect(respDelAS).NotTo(BeNil())
err = configClient.Close()
Expect(err).To(Succeed())
})

It("CreateExternalDataResolverErrorLocation", func() {
Expand Down Expand Up @@ -159,6 +161,8 @@ var _ = Describe("Configuration", func() {
Expect(err).To(MatchError(ContainSubstring(
"insufficient permission to perform requested action")))
Expect(resp).To(BeNil())
err = configClient.Close()
Expect(err).To(Succeed())
})

It("CreateExternalDataResolverWrongMethod", func() {
Expand Down Expand Up @@ -211,6 +215,192 @@ var _ = Describe("Configuration", func() {
respDelAS, err := configClient.DeleteApplicationSpace(context.Background(), reqDelAS)
Expect(err).To(Succeed())
Expect(respDelAS).NotTo(BeNil())
err = configClient.Close()
Expect(err).To(Succeed())
})
})

Describe("EntityMatchingPipeline", func() {
It("CreateEntityMatchingPipeline", func() {
var (
err error
timeNow = fmt.Sprintf("%v", time.Now().UnixNano())
maxRetries = 5
retryDelay = time.Second * 5
)

configClient, err := integration.InitConfigConfig()
Expect(err).To(Succeed())

// create appSpace
displayNamePb := &wrapperspb.StringValue{Value: "AppSpace " + timeNow}
createAppSpaceReq := &configpb.CreateApplicationSpaceRequest{
CustomerId: integration.CustomerID,
Name: "appspace-" + timeNow,
DisplayName: displayNamePb,
Region: "europe-west1",
}
respAppSpace, err := configClient.CreateApplicationSpace(context.Background(), createAppSpaceReq)
Expect(err).To(Succeed())
Expect(respAppSpace).NotTo(BeNil())
appSpaceID := respAppSpace.Id
appSpaceEtag := respAppSpace.Etag

// create config node
configuration := &configpb.EntityMatchingPipelineConfig{
NodeFilter: integration.NodeFilter1,
}
createReq, _ := config.NewCreate("entitymatching-" + timeNow)
createReq.ForLocation(appSpaceID)
createReq.WithDisplayName("EntityMatching" + timeNow)
createReq.WithEntityMatchingPipelineConfig(configuration)

resp, err := configClient.CreateConfigNode(context.Background(), createReq)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite creation config node %v", err)
}
Expect(resp).NotTo(BeNil())
configID := resp.Id
configEtag := resp.Etag
Expect(resp.LocationId).To(Equal(appSpaceID))

// read config node
readReq, _ := config.NewRead(configID)
respRead, err := configClient.ReadConfigNode(context.Background(), readReq)
Expect(err).To(Succeed())
Expect(respRead).NotTo(BeNil())
configNode := respRead.ConfigNode
Expect(configNode).To(PointTo(MatchFields(IgnoreExtras, Fields{
"Id": Equal(configID),
"Name": Equal("entitymatching-" + timeNow),
"Config": PointTo(MatchFields(IgnoreExtras, Fields{
"EntityMatchingPipelineConfig": PointTo(MatchFields(IgnoreExtras, Fields{
"NodeFilter": integration.EqualProto(integration.NodeFilter1),
})),
})),
})))

// update config node
configurationUpd := &configpb.EntityMatchingPipelineConfig{
NodeFilter: integration.NodeFilter2,
}
updateReq, _ := config.NewUpdate(configID)
updateReq.WithDisplayName("EntityMatching2" + timeNow)
updateReq.WithEntityMatchingPipelineConfig(configurationUpd)
respUpd, err := configClient.UpdateConfigNode(context.Background(), updateReq)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite update config node Client %v", err)
}
Expect(respUpd).NotTo(BeNil())
configUpdEtag := respUpd.Etag
Expect(respUpd.Id).To(Equal(configID))
Expect(respUpd.LocationId).To(Equal(appSpaceID))
Expect(configUpdEtag).NotTo(Equal(configEtag))

// delete config node
deleteReq, _ := config.NewDelete(configID)
var respDel *configpb.DeleteConfigNodeResponse
var errDel error
for i := 0; i < maxRetries; i++ {
respDel, errDel = configClient.DeleteConfigNode(context.Background(), deleteReq)
if errDel == nil {
Expect(respDel).NotTo(BeNil())
break // Exit the loop if error is nil
}
time.Sleep(retryDelay) // Wait before retrying
}
// stop delete here: too long in current EM version

// delete appSpace
etagPb := &wrapperspb.StringValue{Value: appSpaceEtag}
reqDelAS := &configpb.DeleteApplicationSpaceRequest{
Id: appSpaceID,
Etag: etagPb,
Bookmarks: []string{},
}
respDelAS, err := configClient.DeleteApplicationSpace(context.Background(), reqDelAS)
Expect(err).To(Succeed())
Expect(respDelAS).NotTo(BeNil())
err = configClient.Close()
Expect(err).To(Succeed())
})

It("CreateEntityMatchingPipelineErrorLocation", func() {
var (
err error
timeNow = fmt.Sprintf("%v", time.Now().UnixNano())
)

configClient, err := integration.InitConfigConfig()
Expect(err).To(Succeed())

configuration := &configpb.EntityMatchingPipelineConfig{
NodeFilter: &configpb.EntityMatchingPipelineConfig_NodeFilter{
SourceNodeTypes: []string{"Employee"},
TargetNodeTypes: []string{"User"},
},
}
createReq, _ := config.NewCreate("entitymatching-" + timeNow)
createReq.ForLocation(integration.WrongAppSpace)
createReq.WithDisplayName("EntityMatching" + timeNow)
createReq.WithEntityMatchingPipelineConfig(configuration)

resp, err := configClient.CreateConfigNode(context.Background(), createReq)
Expect(err).To(MatchError(ContainSubstring(
"insufficient permission to perform requested action")))
Expect(resp).To(BeNil())
err = configClient.Close()
Expect(err).To(Succeed())
})

It("CreateEntityMatchingPipelineWrongNodeFilter", func() {
var (
err error
timeNow = fmt.Sprintf("%v", time.Now().UnixNano())
)

configClient, err := integration.InitConfigConfig()
Expect(err).To(Succeed())

displayNamePb := &wrapperspb.StringValue{Value: "AppSpace " + timeNow}
createAppSpaceReq := &configpb.CreateApplicationSpaceRequest{
CustomerId: integration.CustomerID,
Name: "appspace-" + timeNow,
DisplayName: displayNamePb,
Region: "europe-west1",
}
respAppSpace, err := configClient.CreateApplicationSpace(context.Background(), createAppSpaceReq)
Expect(err).To(Succeed())
Expect(respAppSpace).NotTo(BeNil())
appSpaceID := respAppSpace.Id
appSpaceEtag := respAppSpace.Etag

configuration := &configpb.EntityMatchingPipelineConfig{
NodeFilter: integration.NodeFilter3,
}
createReq, _ := config.NewCreate("entitymatching-" + timeNow)
createReq.ForLocation(appSpaceID)
createReq.WithDisplayName("EntityMatching" + timeNow)
createReq.WithEntityMatchingPipelineConfig(configuration)

resp, err := configClient.CreateConfigNode(context.Background(), createReq)
Expect(err).To(MatchError(ContainSubstring(
"invalid EntityMatchingPipelineConfig_NodeFilter.TargetNodeTypes: " +
"value must contain at least 1 item(s)")))
Expect(resp).To(BeNil())

time.Sleep(5 * time.Second)
etagPb := &wrapperspb.StringValue{Value: appSpaceEtag}
reqDelAS := &configpb.DeleteApplicationSpaceRequest{
Id: appSpaceID,
Etag: etagPb,
Bookmarks: []string{},
}
respDelAS, err := configClient.DeleteApplicationSpace(context.Background(), reqDelAS)
Expect(err).To(Succeed())
Expect(respDelAS).NotTo(BeNil())
err = configClient.Close()
Expect(err).To(Succeed())
})
})
})
18 changes: 0 additions & 18 deletions entitymatching/entitymatching.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@ import (
entitymatchingpb "github.com/indykite/indykite-sdk-go/gen/indykite/entitymatching/v1beta1"
)

func (c *Client) ReadEntityMatchingReport(
ctx context.Context,
req *entitymatchingpb.ReadEntityMatchingReportRequest,
opts ...grpc.CallOption,
) (*entitymatchingpb.ReadEntityMatchingReportResponse, error) {
if err := req.Validate(); err != nil {
return nil, errors.NewInvalidArgumentErrorWithCause(err, "unable to call ReadEntityMatchingReport")
}

ctx = insertMetadata(ctx, c.xMetadata)
resp, err := c.client.ReadEntityMatchingReport(ctx, req, opts...)

if s := errors.FromError(err); s != nil {
return nil, s
}
return resp, nil
}

func (c *Client) ReadSuggestedPropertyMapping(
ctx context.Context,
req *entitymatchingpb.ReadSuggestedPropertyMappingRequest,
Expand Down
48 changes: 0 additions & 48 deletions entitymatching/entitymatching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var _ = Describe("EntityMatching", func() {
mockErrorCode := codes.InvalidArgument
mockErrorMessage := "mockError"
now := time.Now()
oneMonthFromNow := now.AddDate(0, 1, 0)

var (
mockCtrl *gomock.Controller
Expand All @@ -52,53 +51,6 @@ var _ = Describe("EntityMatching", func() {
Ω(err).To(Succeed())
})

Describe("Read Entity Matching Report", func() {
mockReadEntityMatchingReportRequest := entitymatchingpb.ReadEntityMatchingReportRequest{
Id: "gid:886hfic8fswlz3zjrc2e3nun9xs",
}

DescribeTable("ReadEntityMatchingReportSuccess",
func(req *entitymatchingpb.ReadEntityMatchingReportRequest,
beResp *entitymatchingpb.ReadEntityMatchingReportResponse) {
mockClient.EXPECT().ReadEntityMatchingReport(
gomock.Any(),
test.WrapMatcher(test.EqualProto(req)),
gomock.Any(),
).Return(beResp, nil)

resp, err := entitymatchingClient.ReadEntityMatchingReport(context.Background(), req)
Ω(resp).ToNot(BeNil())
Ω(err).To(Succeed())
Ω(resp).To(test.EqualProto(beResp))
},
Entry(
"read entity matching report id and returns response",
&mockReadEntityMatchingReportRequest,
&entitymatchingpb.ReadEntityMatchingReportResponse{
Id: "gid:886hfic8fswlz3zjrc2e3nun9xs",
ReportUrl: "https://report.com",
UrlExpireTime: timestamppb.New(oneMonthFromNow),
EntityMatchingStatus: 3,
},
),
)

It("handles and returns error", func() {
mockClient.EXPECT().ReadEntityMatchingReport(
gomock.Any(),
gomock.Eq(&mockReadEntityMatchingReportRequest),
gomock.Any(),
).Return(nil, status.Error(mockErrorCode, mockErrorMessage))

resp, err := entitymatchingClient.ReadEntityMatchingReport(
context.Background(),
&mockReadEntityMatchingReportRequest)
Ω(resp).To(BeNil())
Ω(err).To(HaveOccurred())
Ω(err).To(test.MatchStatusError(mockErrorCode, mockErrorMessage))
})
})

Describe("Read Suggested Property Mapping", func() {
mockReadSuggestedPropertyMappingRequest := entitymatchingpb.ReadSuggestedPropertyMappingRequest{
Id: "gid:886hfic8fswlz3zjrc2e3nun9xs",
Expand Down
2 changes: 1 addition & 1 deletion examples/config/cmd/entity_matching_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var deleteEntityMatchingPipelineConfigCmd = &cobra.Command{
Use: "delete",
Short: "Delete EntityMatchingPipeline configuration",
Run: func(cmd *cobra.Command, args []string) {
deleteReq, _ := config.NewDelete("gid:AAAAIHQq2n5zkUP0gnFFtcn7hlo")
deleteReq, _ := config.NewDelete("gid:AAAAIBkMrARucEOpqeM6vGJm5b0")
resp, err := client.DeleteConfigNode(context.Background(), deleteReq)
if err != nil {
log.Fatalf("failed to invoke operation on IndyKite Client %v", err)
Expand Down
Loading
Loading