Forma `go fmt` and gingo tests
diff --git a/apigeeSync_suite_test.go b/apigeeSync_suite_test.go index 6d78571..be0f820 100644 --- a/apigeeSync_suite_test.go +++ b/apigeeSync_suite_test.go
@@ -4,17 +4,17 @@ . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "testing" + "encoding/json" "github.com/30x/apid" "github.com/30x/apid/factory" + "github.com/apigee-labs/transicator/common" "io/ioutil" + "net/http" "net/http/httptest" "os" - "encoding/json" - "net/http" - "github.com/apigee-labs/transicator/common" - "time" "strconv" + "testing" + "time" ) var ( @@ -381,7 +381,6 @@ Expect(err).NotTo(HaveOccurred()) }) - var _ = AfterSuite(func() { apid.Events().Close() if testServer != nil {
diff --git a/apigee_sync.go b/apigee_sync.go index f915646..ba9f876 100644 --- a/apigee_sync.go +++ b/apigee_sync.go
@@ -18,7 +18,7 @@ var lastSequence string func addHeaders(req *http.Request) { - req.Header.Add("Authorization", "Bearer " + token) + req.Header.Add("Authorization", "Bearer "+token) req.Header.Set("apid_instance_id", apidInfo.InstanceID) req.Header.Set("apid_cluster_Id", apidInfo.ClusterID) req.Header.Set("updated_at_apid", time.Now().Format(time.RFC3339)) @@ -68,7 +68,7 @@ } endTime := time.Second // Gradually increase retry interval, and max at some level - if endTime - startTime <= 1 { + if endTime-startTime <= 1 { if times < pollInterval { times++ } else {
diff --git a/apigee_sync_test.go b/apigee_sync_test.go index dea238c..5a0ddc7 100644 --- a/apigee_sync_test.go +++ b/apigee_sync_test.go
@@ -1,10 +1,10 @@ package apidApigeeSync import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" "github.com/30x/apid" "github.com/apigee-labs/transicator/common" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" ) var _ = Describe("listener", func() {
diff --git a/data.go b/data.go index 6e9fc2b..565b8c9 100644 --- a/data.go +++ b/data.go
@@ -1,17 +1,17 @@ package apidApigeeSync import ( + "crypto/rand" "database/sql" + "errors" + "fmt" "github.com/30x/apid" "sync" - "fmt" - "crypto/rand" - "errors" ) var ( unsafeDB apid.DB - dbMux sync.RWMutex + dbMux sync.RWMutex ) type dataApidCluster struct { @@ -244,6 +244,10 @@ } func getApidInstanceInfo() (info apidInstanceInfo, err error) { + info.InstanceName = config.GetString(configName) + log.Info("Using the !!!!!!!!!!!!!!!!!!! %s", info.InstanceName) + // not stored in DB + info.ClusterID = config.GetString(configApidClusterId) // always use default database for this var db apid.DB @@ -266,10 +270,6 @@ db.Exec("INSERT INTO APID (instance_id) VALUES (?)", info.InstanceID) } } - info.InstanceName = config.GetString(configName) - // not stored in DB - info.ClusterID = config.GetString(configApidClusterId) - return }
diff --git a/init.go b/init.go index 3d2461a..ff19bed 100644 --- a/init.go +++ b/init.go
@@ -8,24 +8,24 @@ ) const ( - configPollInterval = "apigeesync_poll_interval" - configProxyServerBaseURI = "apigeesync_proxy_server_base" - configSnapServerBaseURI = "apigeesync_snapshot_server_base" + configPollInterval = "apigeesync_poll_interval" + configProxyServerBaseURI = "apigeesync_proxy_server_base" + configSnapServerBaseURI = "apigeesync_snapshot_server_base" configChangeServerBaseURI = "apigeesync_change_server_base" - configConsumerKey = "apigeesync_consumer_key" - configConsumerSecret = "apigeesync_consumer_secret" - configApidClusterId = "apigeesync_cluster_id" - configSnapshotProtocol = "apigeesync_snapshot_proto" - configName = "apigeesync_instance_name" - ApigeeSyncEventSelector = "ApigeeSync" + configConsumerKey = "apigeesync_consumer_key" + configConsumerSecret = "apigeesync_consumer_secret" + configApidClusterId = "apigeesync_cluster_id" + configSnapshotProtocol = "apigeesync_snapshot_proto" + configName = "apigeesync_instance_name" + ApigeeSyncEventSelector = "ApigeeSync" ) var ( - log apid.LogService - config apid.ConfigService - data apid.DataService - events apid.EventsService - apidInfo apidInstanceInfo + log apid.LogService + config apid.ConfigService + data apid.DataService + events apid.EventsService + apidInfo apidInstanceInfo apidPluginDetails string ) @@ -42,27 +42,27 @@ apid.RegisterPlugin(initPlugin) } -func InitDefaults(configService apid.ConfigService) { - configService.SetDefault(configPollInterval, 120) +func initDefaults() { + config.SetDefault(configPollInterval, 120) name, errh := os.Hostname() - if (errh != nil) && (len(configService.GetString(configName)) == 0) { + if (errh != nil) && (len(config.GetString(configName)) == 0) { log.Errorf("Not able to get hostname for kernel. Please set '%s' property in config", configName) name = "Undefined" } - configService.SetDefault(configName, name) - log.Debugf("Using %s as display name", configService.GetString(configName)) + config.SetDefault(configName, name) + log.Debugf("Using %s as display name", config.GetString(configName)) } -func SetLogger(logger apid.LogService) { +func SetLogger(logger apid.LogService) { log = logger } func initPlugin(services apid.Services) (apid.PluginData, error) { - SetLogger(services.Log().ForModule("apigeeSync")); + SetLogger(services.Log().ForModule("apigeeSync")) log.Debug("start init") config = services.Config() - InitDefaults(config); + initDefaults() data = services.Data() events = services.Events() @@ -144,4 +144,3 @@ log.Debug("Done post plugin init") } } -
diff --git a/init_test.go b/init_test.go index c00a1a2..a82502b 100644 --- a/init_test.go +++ b/init_test.go
@@ -1,31 +1,24 @@ -package apidApigeeSync_test; +package apidApigeeSync import ( - "testing" - "github.com/30x/apid" - "github.com/30x/apidApigeeSync" - "github.com/30x/apid/config" - "github.com/30x/apid/logger" - "os" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" ) -func TestInitDefaultsDefaultHostname(t *testing.T) { - var cs apid.ConfigService - cs = config.GetConfig() - apidApigeeSync.SetLogger(logger.NewLogger("init_test.go","DEBUG")) - apidApigeeSync.InitDefaults(cs) - name, _ := os.Hostname() - if cs.Get("apigeesync_instance_name") != name { - t.Errorf("got %s, expected %s", cs.Get("apigeesync_instance_name"),name) - } -} -func TestInitDefaultsNameFromFile(t *testing.T) { - var cs apid.ConfigService - cs = config.GetConfig() - cs.Set("apigeesync_instance_name","myname") - apidApigeeSync.SetLogger(logger.NewLogger("init_test.go","DEBUG")) - apidApigeeSync.InitDefaults(cs) - if cs.Get("apigeesync_instance_name") != "myname" { - t.Errorf("got %s, expected %s", cs.Get("apigeesync_instance_name"),"myname") - } -} +var _ = Describe("init", func() { + + Context("Apid Instance display name", func() { + + It("should be hostname by defauls", func() { + initDefaults() + Expect(apidInfo.InstanceName).To(Equal("testhost")) + }) + It("accept display name from config", func() { + config.Set(configName, "aa01") + initDefaults() + getApidInstanceInfo() + Expect(apidInfo.InstanceName).To(Equal("aa01")) + }) + + }) +})
diff --git a/listener.go b/listener.go index 47c58a7..2a95d6f 100644 --- a/listener.go +++ b/listener.go
@@ -6,8 +6,8 @@ ) const ( - LISTENER_TABLE_APID_CLUSTER = "edgex.apid_cluster" - LISTENER_TABLE_DATA_SCOPE = "edgex.data_scope" + LISTENER_TABLE_APID_CLUSTER = "edgex.apid_cluster" + LISTENER_TABLE_DATA_SCOPE = "edgex.data_scope" ) type handler struct { @@ -122,7 +122,7 @@ log.Panicf("illegal operation: %s for %s", change.Operation, change.Table) } } - if err != nil{ + if err != nil { log.Panicf("Error processing ChangeList: %v", err) } } @@ -167,4 +167,3 @@ return ds } -
diff --git a/listener_test.go b/listener_test.go index 893e81a..ad2c272 100644 --- a/listener_test.go +++ b/listener_test.go
@@ -17,7 +17,7 @@ event := common.Snapshot{ SnapshotInfo: "test_snapshot", - Tables: []common.Table{}, + Tables: []common.Table{}, } handler.Handle(&event) @@ -54,15 +54,15 @@ Name: LISTENER_TABLE_APID_CLUSTER, Rows: []common.Row{ { - "id": &common.ColumnVal{Value: "i"}, - "_change_selector": &common.ColumnVal{Value: "c"}, - "name": &common.ColumnVal{Value: "n"}, + "id": &common.ColumnVal{Value: "i"}, + "_change_selector": &common.ColumnVal{Value: "c"}, + "name": &common.ColumnVal{Value: "n"}, "umbrella_org_app_name": &common.ColumnVal{Value: "o"}, - "created": &common.ColumnVal{Value: "c"}, - "created_by": &common.ColumnVal{Value: "c"}, - "updated": &common.ColumnVal{Value: "u"}, - "updated_by": &common.ColumnVal{Value: "u"}, - "description": &common.ColumnVal{Value: "d"}, + "created": &common.ColumnVal{Value: "c"}, + "created_by": &common.ColumnVal{Value: "c"}, + "updated": &common.ColumnVal{Value: "u"}, + "updated_by": &common.ColumnVal{Value: "u"}, + "description": &common.ColumnVal{Value: "d"}, }, }, }, @@ -70,16 +70,16 @@ Name: LISTENER_TABLE_DATA_SCOPE, Rows: []common.Row{ { - "id": &common.ColumnVal{Value: "i"}, + "id": &common.ColumnVal{Value: "i"}, "_change_selector": &common.ColumnVal{Value: "c"}, - "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"}, + "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"}, }, }, }, @@ -172,7 +172,7 @@ Changes: []common.Change{ { Operation: common.Insert, - Table: LISTENER_TABLE_APID_CLUSTER, + Table: LISTENER_TABLE_APID_CLUSTER, }, }, } @@ -187,7 +187,7 @@ Changes: []common.Change{ { Operation: common.Update, - Table: LISTENER_TABLE_APID_CLUSTER, + Table: LISTENER_TABLE_APID_CLUSTER, }, }, } @@ -206,18 +206,18 @@ Changes: []common.Change{ { Operation: common.Insert, - Table: LISTENER_TABLE_DATA_SCOPE, + Table: LISTENER_TABLE_DATA_SCOPE, NewRow: common.Row{ - "id": &common.ColumnVal{Value: "i"}, + "id": &common.ColumnVal{Value: "i"}, "_change_selector": &common.ColumnVal{Value: "c"}, - "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"}, + "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"}, }, }, }, @@ -263,18 +263,18 @@ Changes: []common.Change{ { Operation: common.Insert, - Table: LISTENER_TABLE_DATA_SCOPE, + Table: LISTENER_TABLE_DATA_SCOPE, NewRow: common.Row{ - "id": &common.ColumnVal{Value: "i"}, + "id": &common.ColumnVal{Value: "i"}, "_change_selector": &common.ColumnVal{Value: "c"}, - "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"}, + "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"}, }, }, }, @@ -287,8 +287,8 @@ Changes: []common.Change{ { Operation: common.Delete, - Table: LISTENER_TABLE_DATA_SCOPE, - OldRow: insert.Changes[0].NewRow, + Table: LISTENER_TABLE_DATA_SCOPE, + OldRow: insert.Changes[0].NewRow, }, }, } @@ -309,7 +309,7 @@ Changes: []common.Change{ { Operation: common.Update, - Table: LISTENER_TABLE_DATA_SCOPE, + Table: LISTENER_TABLE_DATA_SCOPE, }, }, }