From 8ac1c15606ad82ce3013a4587446fba0643578cd Mon Sep 17 00:00:00 2001 From: Cowan Macady Date: Mon, 7 Oct 2024 03:38:19 +0200 Subject: [PATCH] feat: add tests for resolver + modif config implement ENG-4738 --- .github/workflows/pr-test.yaml | 1 + .golangci.yml | 1 - config/config_integration_test.go | 1716 +++-------------------------- grpc/config/credentials.go | 9 - grpc/pool.go | 12 +- helpers/helpers.go | 2 +- test/constants.go | 12 +- test/integration_client.go | 2 +- 8 files changed, 149 insertions(+), 1606 deletions(-) diff --git a/.github/workflows/pr-test.yaml b/.github/workflows/pr-test.yaml index b616f638..cacf988c 100644 --- a/.github/workflows/pr-test.yaml +++ b/.github/workflows/pr-test.yaml @@ -18,6 +18,7 @@ env: INDYKITE_APPLICATION_CREDENTIALS: ${{ secrets.APP_AGENT_CREDENTIALS }} INDYKITE_SERVICE_ACCOUNT_CREDENTIALS: ${{ secrets.SERVICE_ACCOUNT_CREDENTIALS }} TENANT_ID: ${{ secrets.TENANT_ID }} + CUSTOMER_ID: ${{ secrets.CUSTOMER_ID }} PROJECT_ID: jarvis-dev-268314 PROJ_NUMBER: 699926043561 RUN_ENV: staging diff --git a/.golangci.yml b/.golangci.yml index 841e65c7..83c3d0b8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,7 +30,6 @@ linters: - errname - errorlint - exhaustive - - exportloopref - forbidigo - gci - ginkgolinter diff --git a/config/config_integration_test.go b/config/config_integration_test.go index 575be3bd..c66ee664 100644 --- a/config/config_integration_test.go +++ b/config/config_integration_test.go @@ -18,10 +18,11 @@ package config_test import ( "context" + "fmt" "log" "time" - "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry" + "google.golang.org/protobuf/types/known/wrapperspb" "github.com/indykite/indykite-sdk-go/config" configpb "github.com/indykite/indykite-sdk-go/gen/indykite/config/v1beta1" @@ -36,22 +37,29 @@ import ( var _ = Describe("Configuration", func() { Describe("ExternalDataResolver", func() { It("CreateExternalDataResolver", func() { - var err error + 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: "gid:like-real-customer-id", - Name: "like-real-appspace-name", + CustomerId: integration.CustomerID, + Name: "appspace-" + timeNow, DisplayName: displayNamePb, Region: "europe-west1", } - respAppSpace, err := configClient.CreateApplicationSpace(ctx, req) + respAppSpace, err := configClient.CreateApplicationSpace(context.Background(), createAppSpaceReq) Expect(err).To(Succeed()) - Expect(resp).To(test.EqualProto(beResp)) + Expect(respAppSpace).NotTo(BeNil()) + appSpaceId := respAppSpace.Id + appSpaceEtag := respAppSpace.Etag configuration := &configpb.ExternalDataResolverConfig{ - Url: integration.Url, + Url: integration.URL, Method: integration.Method1, Headers: integration.Headers, RequestType: integration.RequestType, @@ -59,1623 +67,147 @@ var _ = Describe("Configuration", func() { ResponseType: integration.ResponseType, ResponseSelector: integration.ResponseSelector, } - createReq, _ := config.NewCreate("like-real-config-node-name2") - createReq.ForLocation("gid:AAAAAvFyVpD_1kd8k2kpNY9rjFM") - createReq.WithDisplayName("Like real ConfigNode Name2") + createReq, _ := config.NewCreate("resolver-" + timeNow) + createReq.ForLocation(appSpaceId) + createReq.WithDisplayName("Resolver" + timeNow) createReq.WithExternalDataResolverConfig(configuration) - resp, err := client.CreateConfigNode(context.Background(), createReq) + resp, err := configClient.CreateConfigNode(context.Background(), createReq) if err != nil { - log.Fatalf("failed to invoke operation on IndyKite Client %v", err) + log.Fatalf("failed to invoke operation on IndyKite creation config node %v", err) } - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id := resp.Info.Changes[0].Id - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeNoProperties", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordNoProperty(externalID, "Individual") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - id := resp.Info.Changes[0].Id - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeDuplicateSameType", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordNoProperty(externalID, "Individual") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).NotTo(BeNil()) - id := resp.Info.Changes[0].Id - - recordb := integration.CreateRecordNoProperty(externalID, "Individual") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(resp2).NotTo(BeNil()) - id2 := resp2.Info.Changes[0].Id - Expect(id2).To(Equal(id)) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeDuplicateDifferentTypes", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordNoProperty(externalID, "Individual") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).NotTo(BeNil()) - id := resp.Info.Changes[0].Id - - recordb := integration.CreateRecordNoProperty(externalID, "Cat") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(resp2).NotTo(BeNil()) - id2 := resp2.Info.Changes[0].Id - Expect(id2).NotTo(Equal(id)) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecord2 := integration.DeleteRecord(externalID, "Cat") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecord2, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeResource", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.UpsertRecordNodeAsset() - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - id := resp.Info.Changes[0].Id - delRecord := integration.DeleteRecord(externalID, "Asset") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeResourceNoProp", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordResourceNoProperty(externalID, "Asset") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - id := resp.Info.Changes[0].Id - delRecord := integration.DeleteRecord(externalID, "Asset") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeDuplicateResourceSameType", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordResourceNoProperty(externalID, "Asset") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) Expect(resp).NotTo(BeNil()) - id := resp.Info.Changes[0].Id - - recordb := integration.CreateRecordResourceNoProperty(externalID, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(resp2).NotTo(BeNil()) - id2 := resp2.Info.Changes[0].Id - Expect(id2).To(Equal(id)) - - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) + configID := resp.Id + configEtag := resp.Etag + Expect(resp.LocationId).To(Equal(appSpaceId)) - delRecord := integration.DeleteRecord(externalID, "Asset") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) + readReq, _ := config.NewRead(configID) + respRead, err := configClient.ReadConfigNode(context.Background(), readReq) Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), + Expect(respRead).NotTo(BeNil()) + configNode := respRead.ConfigNode + Expect(configNode).To(PointTo(MatchFields(IgnoreExtras, Fields{ + "Id": Equal(configID), + "Name": Equal("resolver-" + timeNow), + "Config": PointTo(MatchFields(IgnoreExtras, Fields{ + "ExternalDataResolverConfig": test.EqualProto(configuration), })), }))) - }) - - It("UpsertNodeDuplicateResourceDifferentTypes", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordResourceNoProperty(externalID, "Asset") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).NotTo(BeNil()) - id := resp.Info.Changes[0].Id - recordb := integration.CreateRecordResourceNoProperty(externalID, "Cat") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) + configurationUpd := &configpb.ExternalDataResolverConfig{ + Url: integration.URLUpd, + Method: integration.Method1, + Headers: integration.HeadersUpd, + RequestType: integration.RequestType, + RequestPayload: integration.RequestPayload, + ResponseType: integration.ResponseType, + ResponseSelector: integration.ResponseSelector, + } + updateReq, _ := config.NewUpdate(configID) + updateReq.WithDisplayName("Resolver2" + timeNow) + updateReq.WithExternalDataResolverConfig(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)) + deleteReq, _ := config.NewDelete(configID) + respDel, err := configClient.DeleteConfigNode(context.Background(), deleteReq) Expect(err).To(Succeed()) - Expect(resp2).NotTo(BeNil()) - id2 := resp2.Info.Changes[0].Id - Expect(id2).NotTo(Equal(id)) + Expect(respDel).NotTo(BeNil()) - delRecord := integration.DeleteRecord(externalID, "Cat") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) + etagPb := &wrapperspb.StringValue{Value: appSpaceEtag} + reqDelAS := &configpb.DeleteApplicationSpaceRequest{ + Id: appSpaceId, + Etag: etagPb, + } + respDelAS, err := configClient.DeleteApplicationSpace(context.Background(), reqDelAS) + Expect(err).NotTo(BeNil()) + Expect(respDelAS).To(BeNil()) }) - It("UpsertNodeDuplicateDifferentNodes", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordNoProperty(externalID, "Individual") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).NotTo(BeNil()) - id := resp.Info.Changes[0].Id - - recordb := integration.CreateRecordResourceNoProperty(externalID, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(resp2).NotTo(BeNil()) - id2 := resp2.Info.Changes[0].Id - Expect(id2).NotTo(Equal(id)) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), + It("CreateExternalDataResolverErrorLocation", func() { + var ( + err error + timeNow = fmt.Sprintf("%v", time.Now().UnixNano()) ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - It("UpsertNodeDuplicateTypeNamedResource", func() { - var err error - ingestClient, err := integration.InitConfigIngest() + configClient, err := integration.InitConfigConfig() Expect(err).To(Succeed()) - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordResourceNoProperty(externalID, "Resource") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) + configuration := &configpb.ExternalDataResolverConfig{ + Url: integration.URL, + Method: integration.Method1, + Headers: integration.Headers, + RequestType: integration.RequestType, + RequestPayload: integration.RequestPayload, + ResponseType: integration.ResponseType, + ResponseSelector: integration.ResponseSelector, + } + createReq, _ := config.NewCreate("resolver-" + timeNow) + createReq.ForLocation(integration.WrongAppSpace) + createReq.WithDisplayName("Resolver" + timeNow) + createReq.WithExternalDataResolverConfig(configuration) - Expect(externalID).NotTo(BeNil()) - Expect(err).To(MatchError(ContainSubstring("the type 'Resource' is reserved"))) + resp, err := configClient.CreateConfigNode(context.Background(), createReq) + Expect(err).To(MatchError(ContainSubstring( + "insufficient permission to perform requested action"))) Expect(resp).To(BeNil()) }) - It("DeleteNodeResourceNotExist", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - delRecord := integration.DeleteRecord(externalID, "Asset") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": BeEmpty(), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeDelProperty", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - id := resp.Info.Changes[0].Id - delRecord3 := integration.DeleteRecordWithProperty(externalID, "Individual", "first_name") - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertNodeResourceDelProperty", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.UpsertRecordNodeAsset() - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecord3 := integration.DeleteRecordWithProperty(externalID, "Asset", "colour") - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - id := resp.Info.Changes[0].Id - delRecord := integration.DeleteRecord(externalID, "Asset") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("ResourceDelNotExistingProperty", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - delRecord3 := integration.DeleteRecordWithProperty(externalID, "Asset", "colour") - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": BeEmpty(), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - }) - - Describe("IngestRelationship", func() { - It("UpsertRelationship", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - id := resp.Info.Changes[0].Id - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordResourceNoProperty(externalID2, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id2 := resp2.Info.Changes[0].Id - - record3 := integration.CreateRecordRelationship(externalID, "Individual", externalID2, "Asset", "CAN_SEE") - resp3, err := ingestClient.IngestRecord( - context.Background(), - record3, - retry.WithMax(5), + It("CreateExternalDataResolverWrongMethod", func() { + var ( + err error + timeNow = fmt.Sprintf("%v", time.Now().UnixNano()) ) + configClient, err := integration.InitConfigConfig() Expect(err).To(Succeed()) - Expect(resp3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - id3 := resp3.Info.Changes[0].Id - match := integration.GetRelationship(externalID, "Individual", externalID2, "Asset", "CAN_SEE") - delRecord3 := integration.DeleteRecordRelationship(match) - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) + 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(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id3), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) + Expect(respAppSpace).NotTo(BeNil()) + appSpaceId := respAppSpace.Id + appSpaceEtag := respAppSpace.Etag - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) + configuration := &configpb.ExternalDataResolverConfig{ + Url: integration.URL, + Method: integration.Method3, + RequestType: integration.RequestType, + RequestPayload: integration.RequestPayload, + ResponseType: integration.ResponseType, + ResponseSelector: integration.ResponseSelector, + } + createReq, _ := config.NewCreate("resolver-" + timeNow) + createReq.ForLocation(appSpaceId) + createReq.WithDisplayName("Resolver" + timeNow) + createReq.WithExternalDataResolverConfig(configuration) - delRecordb := integration.DeleteRecord(externalID2, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) + resp, err := configClient.CreateConfigNode(context.Background(), createReq) + Expect(err).To(MatchError(ContainSubstring( + "invalid ExternalDataResolverConfig.Method: value must be in list [GET POST PUT PATCH]"))) + Expect(resp).To(BeNil()) - It("UpsertRelationshipDeleteWrongSource", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id := resp.Info.Changes[0].Id - - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordResourceNoProperty(externalID2, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id2 := resp2.Info.Changes[0].Id - - record3 := integration.CreateRecordRelationship(externalID, "Individual", externalID2, "Asset", "CAN_SEE") - resp3, err := ingestClient.IngestRecord( - context.Background(), - record3, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - - match := integration.GetRelationship("whatever", "Individual", externalID2, "Asset", "CAN_SEE") - delRecord3 := integration.DeleteRecordRelationship(match) - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertRelationshipDeleteWrongSourceType", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id := resp.Info.Changes[0].Id - - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordResourceNoProperty(externalID2, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id2 := resp2.Info.Changes[0].Id - - record3 := integration.CreateRecordRelationship(externalID, "Individual", externalID2, "Asset", "CAN_SEE") - resp3, err := ingestClient.IngestRecord( - context.Background(), - record3, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - - match := integration.GetRelationship(externalID2, "Whatever", externalID2, "Asset", "CAN_SEE") - delRecord3 := integration.DeleteRecordRelationship(match) - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertRelationshipWrongSourceType", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id := resp.Info.Changes[0].Id - - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordResourceNoProperty(externalID2, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id2 := resp2.Info.Changes[0].Id - - record3 := integration.CreateRecordRelationship(externalID, "Whatever", externalID2, "Asset", "CAN_SEE") - resp3, err := ingestClient.IngestRecord( - context.Background(), - record3, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - - match := integration.GetRelationship(externalID, "Whatever", externalID2, "Asset", "CAN_SEE") - delRecord3 := integration.DeleteRecordRelationship(match) - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).NotTo(BeNil()) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertRelationshipWrongSource", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id := resp.Info.Changes[0].Id - - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordResourceNoProperty(externalID2, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id2 := resp2.Info.Changes[0].Id - rel := integration.GenerateRandomString(10) - - record3 := integration.CreateRecordRelationship(rel, "Individual", externalID2, "Asset", "CAN_SEE") - resp3, err := ingestClient.IngestRecord( - context.Background(), - record3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(resp3).NotTo(BeNil()) - - match := integration.GetRelationship(rel, "Individual", externalID2, "Asset", "CAN_SEE") - delRecord3 := integration.DeleteRecordRelationship(match) - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).NotTo(BeNil()) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertRelationshipActionLowercase", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id := resp.Info.Changes[0].Id - - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordResourceNoProperty(externalID2, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id2 := resp2.Info.Changes[0].Id - - record3 := integration.CreateRecordRelationship(externalID, "Individual", externalID2, "Asset", "can_see") - resp3, err := ingestClient.IngestRecord( - context.Background(), - record3, - retry.WithMax(5), - ) - Expect(err).To(MatchError(ContainSubstring( - "invalid Relationship.Type: value does not match regex pattern \"^[A-Z]+(?:_[A-Z]+)*$\""))) - Expect(resp3).To(BeNil()) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("UpsertRelationshipDelProperty", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - record, externalID := integration.CreateRecordNodeIndividual("Employee") - resp, err := ingestClient.IngestRecord( - context.Background(), - record, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id := resp.Info.Changes[0].Id - - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordResourceNoProperty(externalID2, "Asset") - resp2, err := ingestClient.IngestRecord( - context.Background(), - recordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(resp2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - id2 := resp2.Info.Changes[0].Id - - record3 := integration.CreateRecordRelationship(externalID, "Individual", externalID2, "Asset", "CAN_SEE") - resp3, err := ingestClient.IngestRecord( - context.Background(), - record3, - retry.WithMax(5), - ) - - Expect(err).To(Succeed()) - Expect(resp3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - - delRecord3 := integration.DeleteRecordRelationshipProperty( - externalID, - "Individual", - externalID2, - "Asset", - "CAN_SEE", - "property1", - ) - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Asset") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Equal(id2), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("RelationshipDelNotExistingProperty", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - externalID2 := integration.GenerateRandomString(10) - delRecord3 := integration.DeleteRecordRelationshipProperty( - externalID, - "Individual", - externalID2, - "Asset", - "CAN_SEE", - "property1", - ) - del3, err := ingestClient.IngestRecord( - context.Background(), - delRecord3, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del3).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "DataType": Equal(ingestpb.DataType_DATA_TYPE_RELATIONSHIP), - }))), - })), - }))) - }) - }) - - Describe("Stream", func() { - It("StreamSendRecord", func() { - var err, err2 error - - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordNoProperty(externalID, "Individual") - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordNoProperty(externalID2, "Individual") - - records := []*ingestpb.Record{ - record, recordb, - } - - ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) - defer cancel() - - err2 = ingestClient.OpenStreamClient(ctx) - Expect(err2).To(Succeed()) - - for _, record := range records { - err3 := ingestClient.SendRecord(record) - Expect(err3).To(Succeed()) - resp, err4 := ingestClient.ReceiveResponse() - Expect(err4).To(Succeed()) - Expect(resp).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - } - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Individual") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("StreamRecords", func() { - var err error - ingestClient, err := integration.InitConfigIngest() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordNoProperty(externalID, "Individual") - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordNoProperty(externalID2, "Individual") - - records := []*ingestpb.Record{ - record, recordb, - } - responses, err := ingestClient.StreamRecords(records) - Expect(err).To(Succeed()) - for _, response := range responses { - Expect(response).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Error": BeNil(), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) + etagPb := &wrapperspb.StringValue{Value: appSpaceEtag} + reqDelAS := &configpb.DeleteApplicationSpaceRequest{ + Id: appSpaceId, + Etag: etagPb, } - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Individual") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - }) - - It("StreamRecordsRetry", func() { - var err error - ingestClient, err := integration.InitConfigIngestRetry() - Expect(err).To(Succeed()) - - externalID := integration.GenerateRandomString(10) - record := integration.CreateRecordNoProperty(externalID, "Individual") - externalID2 := integration.GenerateRandomString(10) - recordb := integration.CreateRecordNoProperty(externalID2, "Individual") - - records := []*ingestpb.Record{ - record, recordb, - } - responses, err := ingestClient.StreamRecords(records) - Expect(err).To(Succeed()) - for _, response := range responses { - Expect(response).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Error": BeNil(), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - } - - delRecord := integration.DeleteRecord(externalID, "Individual") - del, err := ingestClient.IngestRecord( - context.Background(), - delRecord, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) - - delRecordb := integration.DeleteRecord(externalID2, "Individual") - del2, err := ingestClient.IngestRecord( - context.Background(), - delRecordb, - retry.WithMax(5), - ) - Expect(err).To(Succeed()) - Expect(del2).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RecordId": Not(BeNil()), - "Info": PointTo(MatchFields(IgnoreExtras, Fields{ - "Changes": ContainElement(PointTo(MatchFields(IgnoreExtras, Fields{ - "Id": Not(BeEmpty()), - "DataType": Equal(ingestpb.DataType_DATA_TYPE_NODE), - }))), - })), - }))) + respDelAS, err := configClient.DeleteApplicationSpace(context.Background(), reqDelAS) + Expect(err).NotTo(BeNil()) + Expect(respDelAS).To(BeNil()) }) }) }) diff --git a/grpc/config/credentials.go b/grpc/config/credentials.go index 4ff94b85..413832a8 100644 --- a/grpc/config/credentials.go +++ b/grpc/config/credentials.go @@ -55,15 +55,6 @@ func DefaultEnvironmentLoaderConfig(_ context.Context) (*CredentialsConfig, erro return UnmarshalCredentialConfig(data) } -// EntityMatchingEnvironmentLoader for backward compatibility with old environment variables. -func EntityMatchingEnvironmentLoader(_ context.Context) (*CredentialsConfig, error) { - data, err := lookupEnvCredentialVariables("INDYKITE_ENTITY_MATCHING_APPLICATION_CREDENTIALS") - if err != nil { - return nil, err - } - return UnmarshalCredentialConfig(data) -} - func StaticCredentialsJSON(credentialsJSON []byte) CredentialsLoader { return func(_ context.Context) (*CredentialsConfig, error) { return UnmarshalCredentialConfig(credentialsJSON) diff --git a/grpc/pool.go b/grpc/pool.go index 433ecb7a..c6f45f23 100644 --- a/grpc/pool.go +++ b/grpc/pool.go @@ -23,6 +23,7 @@ package grpc import ( "context" "fmt" + "math" "sync/atomic" "google.golang.org/grpc" @@ -75,7 +76,16 @@ func (p *roundRobinConnPool) Num() int { func (p *roundRobinConnPool) Conn() *grpc.ClientConn { i := atomic.AddUint32(&p.idx, 1) - return p.conns[i%uint32(len(p.conns))] + v := len(p.conns) + // Check for negative values + if v < 0 { + return nil + } + // Check for overflow + if v > int(math.MaxUint32) { + return nil + } + return p.conns[i%uint32(v)] } func (p *roundRobinConnPool) Close() error { diff --git a/helpers/helpers.go b/helpers/helpers.go index 730cb873..7f0de62a 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -54,7 +54,7 @@ func (c *Client) DeleteNodes( } records = append(records, record) } - responses, err := c.ClientIngest.StreamRecords(records) //nolint: contextcheck // against StreamRecords + responses, err := c.ClientIngest.StreamRecords(records) //nolint:contextcheck // against StreamRecords if err != nil { return nil, err } diff --git a/test/constants.go b/test/constants.go index 552f0268..9a352293 100644 --- a/test/constants.go +++ b/test/constants.go @@ -17,6 +17,7 @@ package test import ( "crypto/rand" "encoding/base64" + "os" "github.com/google/uuid" "google.golang.org/protobuf/types/known/timestamppb" @@ -192,17 +193,26 @@ var ( ConsentAllow = "gid:AAAAHf5ZnwufDUK-tnCjoSsw-cQ" Resolver = "gid:AAAAIcrOChFSj0R5sFm1V8JXhiE" - Url = "https://example.com/source2" + URL = "https://example.com/source2" + URLUpd = "https://example.com/sourceupd" Method1 = "GET" Method2 = "POST" + Method3 = "ACTION" Headers = map[string]*configpb.ExternalDataResolverConfig_Header{ "Authorization": {Values: []string{"Bearer edolkUTY"}}, "Content-Type": {Values: []string{"application/json"}}, } + HeadersUpd = map[string]*configpb.ExternalDataResolverConfig_Header{ + "Authorization": {Values: []string{"Bearer pdnYhjui"}}, + "Content-Type": {Values: []string{"application/json"}}, + } RequestType = configpb.ExternalDataResolverConfig_CONTENT_TYPE_JSON RequestPayload = []byte(`{"key": "value"}`) ResponseType = configpb.ExternalDataResolverConfig_CONTENT_TYPE_JSON ResponseSelector = "." + + CustomerID = os.Getenv("CUSTOMER_ID") + WrongAppSpace = "gid:AAAAAgDRZxyY6Ecrjhj2GMCtgVI" ) func GenerateRandomString(length int) string { diff --git a/test/integration_client.go b/test/integration_client.go index 762efc3d..e1af424a 100644 --- a/test/integration_client.go +++ b/test/integration_client.go @@ -88,7 +88,7 @@ func InitConfigIngestRetry() (*ingest.RetryClient, error) { func InitConfigConfig() (*config.Client, error) { clientConfig, err = config.NewClient(context.Background(), grpc.WithCredentialsLoader(apicfg.DefaultEnvironmentLoaderConfig), - grpc.WithRetryOptions(retry.Disable()), + grpc.WithServiceAccount(), ) if err != nil { er(fmt.Sprintf("failed to create IndyKite Config Client: %v", err))