Compelte TCs for Changes.
diff --git a/listener_test.go b/listener_test.go index aac6225..2a91b90 100644 --- a/listener_test.go +++ b/listener_test.go
@@ -4,6 +4,7 @@ "encoding/json" "github.com/30x/apid" . "github.com/30x/apidApigeeSync" // for direct access to Payload types + "github.com/30x/transicator/common" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -12,69 +13,186 @@ It("should store data from ApigeeSync in the database", func(done Done) { - var event = ChangeSet{} - event.Changes = []ChangePayload{ + var event = common.ChangeList{} + /* API Product */ + srvItems := common.Row{} + scv := &common.ColumnVal{ + Value: "ch_api_product_0", + Type: 1, + } + srvItems["id"] = scv + + scv = &common.ColumnVal{ + Value: "{}", + Type: 1, + } + srvItems["api_resources"] = scv + + scv = &common.ColumnVal{ + Value: "{Env_0, Env_1}", + Type: 1, + } + srvItems["environments"] = scv + + scv = &common.ColumnVal{ + Value: "tenant_id_0", + Type: 1, + } + srvItems["tenant_id"] = scv + + scv = &common.ColumnVal{ + Value: "test_org0", + Type: 1, + } + srvItems["_apid_scope"] = scv + + /* DEVELOPER */ + devItems := common.Row{} + scv = &common.ColumnVal{ + Value: "ch_developer_id_0", + Type: 1, + } + devItems["id"] = scv + + scv = &common.ColumnVal{ + Value: "Active", + Type: 1, + } + devItems["status"] = scv + + scv = &common.ColumnVal{ + Value: "tenant_id_0", + Type: 1, + } + devItems["tenant_id"] = scv + + scv = &common.ColumnVal{ + Value: "test_org0", + Type: 1, + } + devItems["_apid_scope"] = scv + + /* APP */ + appItems := common.Row{} + scv = &common.ColumnVal{ + Value: "ch_application_id_0", + Type: 1, + } + appItems["id"] = scv + + scv = &common.ColumnVal{ + Value: "ch_developer_id_0", + Type: 1, + } + appItems["developer_id"] = scv + + scv = &common.ColumnVal{ + Value: "tenant_id_0", + Type: 1, + } + appItems["tenant_id"] = scv + + scv = &common.ColumnVal{ + Value: "Approved", + Type: 1, + } + appItems["status"] = scv + + scv = &common.ColumnVal{ + Value: "test_org0", + Type: 1, + } + appItems["_apid_scope"] = scv + + /* CRED */ + credItems := common.Row{} + scv = &common.ColumnVal{ + Value: "ch_app_credential_0", + Type: 1, + } + credItems["id"] = scv + + scv = &common.ColumnVal{ + Value: "ch_application_id_0", + Type: 1, + } + credItems["app_id"] = scv + + scv = &common.ColumnVal{ + Value: "tenant_id_0", + Type: 1, + } + credItems["tenant_id"] = scv + + scv = &common.ColumnVal{ + Value: "Approved", + Type: 1, + } + credItems["status"] = scv + + scv = &common.ColumnVal{ + Value: "test_org0", + Type: 1, + } + credItems["_apid_scope"] = scv + + /* APP_CRED_APIPRD_MAPPER */ + mpItems := common.Row{} + scv = &common.ColumnVal{ + Value: "ch_api_product_0", + Type: 1, + } + mpItems["apiprdt_id"] = scv + + scv = &common.ColumnVal{ + Value: "ch_application_id_0", + Type: 1, + } + mpItems["app_id"] = scv + + scv = &common.ColumnVal{ + Value: "ch_app_credential_0", + Type: 1, + } + mpItems["appcred_id"] = scv + + scv = &common.ColumnVal{ + Value: "Approved", + Type: 1, + } + mpItems["status"] = scv + + scv = &common.ColumnVal{ + Value: "test_org0", + Type: 1, + } + mpItems["_apid_scope"] = scv + + event.Changes = []common.Change{ { - Data: DataPayload{ - EntityType: "apiproduct", - Operation: "create", - PldCont: Payload{ - Organization: "test_org", - AppName: "Api_product_sync", - Resources: []string{"/**", "/test"}, - Environments: []string{"Env_0", "Env_1"}, - }, - }, + Table: "public.api_product", + NewRow: srvItems, + Operation: 1, }, { - Data: DataPayload{ - EntityType: "developer", - Operation: "create", - EntityIdentifier: "developer_id_sync", - PldCont: Payload{ - Organization: "test_org", - Email: "person_sync@apigee.com", - Status: "Active", - UserName: "user_sync", - FirstName: "user_first_name_sync", - LastName: "user_last_name_sync", - }, - }, + Table: "public.developer", + NewRow: devItems, + Operation: 1, }, { - Data: DataPayload{ - EntityType: "app", - Operation: "create", - EntityIdentifier: "application_id_sync", - PldCont: Payload{ - Organization: "test_org", - Email: "person_sync@apigee.com", - Status: "Approved", - AppName: "application_id_sync", - DeveloperId: "developer_id_sync", - CallbackUrl: "call_back_url", - }, - }, + Table: "public.app", + NewRow: appItems, + Operation: 1, }, { - Data: DataPayload{ - EntityType: "credential", - Operation: "create", - EntityIdentifier: "credential_sync", - PldCont: Payload{ - Organization: "test_org", - AppId: "application_id_sync", - Status: "Approved", - ConsumerSecret: "consumer_secret_sync", - IssuedAt: 349583485, - ApiProducts: []Apip{ - { - ApiProduct: "Api_product_sync", - Status: "Approved", - }, - }, - }, - }, + Table: "public.app_credential", + NewRow: credItems, + Operation: 1, + }, + { + Table: "public.app_credential_apiproduct_mapper", + NewRow: mpItems, + Operation: 1, }, } @@ -83,26 +201,26 @@ func(e apid.Event) { // ignore the first event, let standard listener process it - changeSet := e.(*ChangeSet) + changeSet := e.(*common.ChangeList) if len(changeSet.Changes) > 0 { return } - - rsp, err := verifyAPIKey("credential_sync", "/test", "Env_0", "test_org", "verify") + processChange(changeSet) + rsp, err := verifyAPIKey("ch_app_credential_0", "/test", "Env_0", "test_org0", "verify") Expect(err).ShouldNot(HaveOccurred()) var respj kmsResponseSuccess json.Unmarshal(rsp, &respj) Expect(respj.Type).Should(Equal("APIKeyContext")) - Expect(respj.RspInfo.Key).Should(Equal("credential_sync")) + Expect(respj.RspInfo.Key).Should(Equal("ch_app_credential_0")) close(done) }, } apid.Events().Listen(ApigeeSyncEventSelector, h) - apid.Events().Emit(ApigeeSyncEventSelector, &event) // for standard listener - apid.Events().Emit(ApigeeSyncEventSelector, &ChangeSet{}) // for test listener + apid.Events().Emit(ApigeeSyncEventSelector, &event) // for standard listener + apid.Events().Emit(ApigeeSyncEventSelector, &common.ChangeList{}) // for test listener }) })
diff --git a/validate_path.go b/validate_path.go index ac107cb..cd6e021 100644 --- a/validate_path.go +++ b/validate_path.go
@@ -39,7 +39,6 @@ * FIXME: SINGLE_FORWARD_SLASH_PATTERN not supported yet */ } - /* if the i/p resource is empty, no checks need to be made */ - return len(fs) == 0 + return s == "" }
diff --git a/validate_path_test.go b/validate_path_test.go index 56e4d50..a5e5e63 100644 --- a/validate_path_test.go +++ b/validate_path_test.go
@@ -20,11 +20,11 @@ Expect(s).Should(BeTrue()) }) It("validation4", func() { - s := validatePath("{\"/**\"}", "/foo") + s := validatePath("{/**}", "/foo") Expect(s).Should(BeTrue()) }) It("validation5", func() { - s := validatePath("{\"/**\"}", "foo") + s := validatePath("{/**}", "foo") Expect(s).Should(BeFalse()) }) It("validation6", func() {