code cleanup
diff --git a/apigee_sync_test.go b/apigee_sync_test.go index 10b553d..463b9e4 100644 --- a/apigee_sync_test.go +++ b/apigee_sync_test.go
@@ -57,14 +57,14 @@ expectedSnapshotTables := common.ChangeList{ Changes: []common.Change{common.Change{Table: "kms_company"}, - common.Change{Table: "edgex_apid_cluster"}, - common.Change{Table: "edgex_data_scope"}, - common.Change{Table: "kms_app_credential"}, - common.Change{Table: "kms_app_credential_apiproduct_mapper"}, - common.Change{Table: "kms_developer"}, - common.Change{Table: "kms_company_developer"}, - common.Change{Table: "kms_api_product"}, - common.Change{Table: "kms_app"}}, + common.Change{Table: "edgex_apid_cluster"}, + common.Change{Table: "edgex_data_scope"}, + common.Change{Table: "kms_app_credential"}, + common.Change{Table: "kms_app_credential_apiproduct_mapper"}, + common.Change{Table: "kms_developer"}, + common.Change{Table: "kms_company_developer"}, + common.Change{Table: "kms_api_product"}, + common.Change{Table: "kms_app"}}, } apid.Events().ListenFunc(ApigeeSyncEventSelector, func(event apid.Event) { @@ -170,8 +170,8 @@ initializeContext() expectedTables := common.ChangeList{ Changes: []common.Change{common.Change{Table: "kms_company"}, - common.Change{Table: "edgex_apid_cluster"}, - common.Change{Table: "edgex_data_scope"}}, + common.Change{Table: "edgex_apid_cluster"}, + common.Change{Table: "edgex_data_scope"}}, } Expect(apidInfo.LastSnapshot).NotTo(BeEmpty()) @@ -339,4 +339,4 @@ }, 3) }) -}) \ No newline at end of file +})
diff --git a/data.go b/data.go index c9b7e2a..0f45ea2 100644 --- a/data.go +++ b/data.go
@@ -112,7 +112,6 @@ func getValueListFromKeys(row common.Row, pkeys []string) []interface{} { var values []interface{} - // TODO Handle multiple data types for _, pkey := range pkeys { if row[pkey] == nil { values = append(values, nil) @@ -133,7 +132,6 @@ log.Errorf("No rows found for table.", tableName) return false } else { - sql := buildDeleteSql(tableName, rows[0], pkeys) prep, err := txn.Prepare(sql) if err != nil { @@ -351,36 +349,6 @@ return strings.Replace(tableName, ".", "_", 1) } -func insertApidCluster(dac dataApidCluster, txn *sql.Tx) error { - - log.Debugf("inserting into APID_CLUSTER: %v", dac) - - //replace to accomodate same snapshot txid - stmt, err := txn.Prepare(` - REPLACE INTO APID_CLUSTER - (id, description, name, umbrella_org_app_name, - created, created_by, updated, updated_by, - last_sequence) - VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9); - `) - if err != nil { - log.Errorf("prepare insert into APID_CLUSTER transaction Failed: %v", err) - return err - } - defer stmt.Close() - - _, err = stmt.Exec( - dac.ID, dac.Description, dac.Name, dac.OrgAppName, - dac.Created, dac.CreatedBy, dac.Updated, dac.UpdatedBy, - "") - - if err != nil { - log.Errorf("insert APID_CLUSTER failed: %v", err) - } - - return err -} - /* * For the given apidConfigId, this function will retrieve all the distinch scopes * associated with it. Distinct, because scope is already a collection of the tenants.
diff --git a/init.go b/init.go index 7ac68a2..1e15099 100644 --- a/init.go +++ b/init.go
@@ -126,8 +126,8 @@ } } proto := config.GetString(configSnapshotProtocol) - if proto != "json" && proto != "proto" && proto != "sqlite" { - return fmt.Errorf("Illegal value for %s. Must be: 'json', 'proto', or 'sqlite'", configSnapshotProtocol) + if proto != "sqlite" { + return fmt.Errorf("Illegal value for %s. Only currently supported snashot protocol is sqlite", configSnapshotProtocol) } return nil
diff --git a/listener.go b/listener.go index fd0a5a8..a1360d4 100644 --- a/listener.go +++ b/listener.go
@@ -50,7 +50,6 @@ } - func processSqliteSnapshot(db apid.DB) { var numApidClusters int
diff --git a/listener_test.go b/listener_test.go index 7d4af9b..2c9c1c6 100644 --- a/listener_test.go +++ b/listener_test.go
@@ -12,7 +12,7 @@ handler := handler{} - var createTestDb = func (sqlfile string, dbId string) common.Snapshot{ + var createTestDb = func(sqlfile string, dbId string) common.Snapshot { initDb(sqlfile, "./mockdb.sqlite3") file, err := os.Open("./mockdb.sqlite3") if err != nil { @@ -200,15 +200,15 @@ Operation: common.Insert, Table: LISTENER_TABLE_DATA_SCOPE, NewRow: common.Row{ - "id": &common.ColumnVal{Value: "i"}, - "apid_cluster_id": &common.ColumnVal{Value: "a"}, - "scope": &common.ColumnVal{Value: "s1"}, - "org": &common.ColumnVal{Value: "o"}, - "env": &common.ColumnVal{Value: "e"}, - "created": &common.ColumnVal{Value: "c"}, - "created_by": &common.ColumnVal{Value: "c"}, - "updated": &common.ColumnVal{Value: "u"}, - "updated_by": &common.ColumnVal{Value: "u"}, + "id": &common.ColumnVal{Value: "i"}, + "apid_cluster_id": &common.ColumnVal{Value: "a"}, + "scope": &common.ColumnVal{Value: "s1"}, + "org": &common.ColumnVal{Value: "o"}, + "env": &common.ColumnVal{Value: "e"}, + "created": &common.ColumnVal{Value: "c"}, + "created_by": &common.ColumnVal{Value: "c"}, + "updated": &common.ColumnVal{Value: "u"}, + "updated_by": &common.ColumnVal{Value: "u"}, "_change_selector": &common.ColumnVal{Value: "cs"}, }, }, @@ -216,15 +216,15 @@ Operation: common.Insert, Table: LISTENER_TABLE_DATA_SCOPE, NewRow: common.Row{ - "id": &common.ColumnVal{Value: "j"}, - "apid_cluster_id": &common.ColumnVal{Value: "a"}, - "scope": &common.ColumnVal{Value: "s2"}, - "org": &common.ColumnVal{Value: "o"}, - "env": &common.ColumnVal{Value: "e"}, - "created": &common.ColumnVal{Value: "c"}, - "created_by": &common.ColumnVal{Value: "c"}, - "updated": &common.ColumnVal{Value: "u"}, - "updated_by": &common.ColumnVal{Value: "u"}, + "id": &common.ColumnVal{Value: "j"}, + "apid_cluster_id": &common.ColumnVal{Value: "a"}, + "scope": &common.ColumnVal{Value: "s2"}, + "org": &common.ColumnVal{Value: "o"}, + "env": &common.ColumnVal{Value: "e"}, + "created": &common.ColumnVal{Value: "c"}, + "created_by": &common.ColumnVal{Value: "c"}, + "updated": &common.ColumnVal{Value: "u"}, + "updated_by": &common.ColumnVal{Value: "u"}, "_change_selector": &common.ColumnVal{Value: "cs"}, }, }, @@ -284,15 +284,15 @@ Operation: common.Insert, Table: LISTENER_TABLE_DATA_SCOPE, NewRow: common.Row{ - "id": &common.ColumnVal{Value: "i"}, - "apid_cluster_id": &common.ColumnVal{Value: "a"}, - "scope": &common.ColumnVal{Value: "s"}, - "org": &common.ColumnVal{Value: "o"}, - "env": &common.ColumnVal{Value: "e"}, - "created": &common.ColumnVal{Value: "c"}, - "created_by": &common.ColumnVal{Value: "c"}, - "updated": &common.ColumnVal{Value: "u"}, - "updated_by": &common.ColumnVal{Value: "u"}, + "id": &common.ColumnVal{Value: "i"}, + "apid_cluster_id": &common.ColumnVal{Value: "a"}, + "scope": &common.ColumnVal{Value: "s"}, + "org": &common.ColumnVal{Value: "o"}, + "env": &common.ColumnVal{Value: "e"}, + "created": &common.ColumnVal{Value: "c"}, + "created_by": &common.ColumnVal{Value: "c"}, + "updated": &common.ColumnVal{Value: "u"}, + "updated_by": &common.ColumnVal{Value: "u"}, "_change_selector": &common.ColumnVal{Value: "cs"}, }, },
diff --git a/mock_server.go b/mock_server.go index 236b97d..dacdd58 100644 --- a/mock_server.go +++ b/mock_server.go
@@ -13,15 +13,15 @@ "net" + "database/sql" "github.com/30x/apid-core" "github.com/apigee-labs/transicator/common" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "strconv" - "os" "io" - "database/sql" "io/ioutil" + "os" + "strconv" ) /* @@ -44,16 +44,16 @@ const oauthExpiresIn = 2 * 60 // 2 minutes type MockParms struct { - ReliableAPI bool - ClusterID string - TokenKey string - TokenSecret string - Scope string - Organization string - Environment string - NumDevelopers int - NumDeployments int - BundleURI string + ReliableAPI bool + ClusterID string + TokenKey string + TokenSecret string + Scope string + Organization string + Environment string + NumDevelopers int + NumDeployments int + BundleURI string } func Mock(params MockParms, router apid.Router) *MockServer {
diff --git a/snapshot.go b/snapshot.go index b9afe38..2389d5f 100644 --- a/snapshot.go +++ b/snapshot.go
@@ -274,12 +274,12 @@ var processSnapshotResponse func(string, io.Reader, *common.Snapshot) error - if config.GetString(configSnapshotProtocol) == "sqlite" { - req.Header.Set("Accept", "application/transicator+sqlite") - processSnapshotResponse = processSnapshotServerFileResponse - } else { + if config.GetString(configSnapshotProtocol) != "sqlite" { log.Panic("Only currently supported snashot protocol is sqlite") + } + req.Header.Set("Accept", "application/transicator+sqlite") + processSnapshotResponse = processSnapshotServerFileResponse // Issue the request to the snapshot server r, err := httpclient.Do(req)
diff --git a/token.go b/token.go index cf5cec5..424c8d4 100644 --- a/token.go +++ b/token.go
@@ -242,4 +242,4 @@ return true } return time.Now().Add(refreshFloatTime).After(t.ExpiresAt) -} \ No newline at end of file +}
diff --git a/token_test.go b/token_test.go index ab48eff..c8ec7ba 100644 --- a/token_test.go +++ b/token_test.go
@@ -199,4 +199,4 @@ close(done) }, 3) }) -}) \ No newline at end of file +})