From 6e4dc1a757a42c2bfc69871d3a7e15bddaa7c13a Mon Sep 17 00:00:00 2001 From: "jackdaw@loafle.com" Date: Fri, 28 Apr 2017 11:38:52 +0900 Subject: [PATCH] config read test --- config_manager/config_test.go | 61 +++++++++++++++++++++++++++++++++++ config_manager/test.json | 50 ++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 config_manager/config_test.go create mode 100644 config_manager/test.json diff --git a/config_manager/config_test.go b/config_manager/config_test.go new file mode 100644 index 0000000..968b0eb --- /dev/null +++ b/config_manager/config_test.go @@ -0,0 +1,61 @@ +package config_manager + +import ( + "testing" + "io/ioutil" + "log" + "encoding/json" + "github.com/stretchr/testify/assert" +) + +func TestConfigRead(t *testing.T) { + + + b, err := ioutil.ReadFile("/root/gowork/src/loafle.com/overflow/agent_api/config_manager/test.json") + if err != nil { + log.Panic(err) + } + var m = Config{} + json.Unmarshal(b, &m) + + assert.Equal(t, m.Id,"123980918237") + assert.Equal(t, m.Target.Connection.Ip,"192.168.1.103") + assert.Equal(t, m.Target.Connection.Port,"1433") + assert.Equal(t, m.Target.Connection.SSL,false) + assert.Equal(t, m.Target.Connection.PortType,"tcp") + + assert.Equal(t, m.Target.Auth["url"],"jdbc:sqlserver://192.168.1.106:1433;") + assert.Equal(t, m.Target.Auth["id"],"sa") + assert.Equal(t, m.Target.Auth["pw"],"qwe123") + assert.Equal(t, m.Target.Auth["query"],"select * from master.dbo.sysprocesses") + + assert.Equal(t, m.Schedule.Interval,"10") + + assert.Equal(t, m.Crawler.Name,"health_activedirectory") + assert.Equal(t, m.Crawler.Container,"network_proxy") + + item := m.Items[0] + + assert.Equal(t, item.Keys[0].Metric,"object[$0].db[$1].datafile_size") + assert.Equal(t, item.Keys[0].Key,"Data File(s) Size (KB)") + + assert.Equal(t, item.Keys[1].Metric,"object[$0].db[$1].logfile_size") + assert.Equal(t, item.Keys[1].Key,"Log File(s) Size (KB)") + + assert.Equal(t, item.QueryInfo.Query,"select object_name,instance_name, counter_name, cntr_value from sys.dm_os_performance_counters where ( counter_name = 'Data File(s) Size (KB)' or counter_name = 'Log File(s) Size (KB)' ) AND object_name = 'SQLServer:Databases'") + assert.Equal(t, item.QueryInfo.Extend["test"],"test") + + assert.Equal(t, item.MappingInfo.ParseDirection,"row") + assert.Equal(t, item.MappingInfo.ArrayColumns[0],"object_name") + assert.Equal(t, item.MappingInfo.ArrayColumns[1],"instance_name") + + assert.Equal(t, item.MappingInfo.KeyColumns[0],"counter_name") + assert.Equal(t, item.MappingInfo.ValueColumn,"cntr_value") + + + + + + + +} \ No newline at end of file diff --git a/config_manager/test.json b/config_manager/test.json new file mode 100644 index 0000000..3bce50f --- /dev/null +++ b/config_manager/test.json @@ -0,0 +1,50 @@ +{ + "id" : "123980918237", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "1433", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "url":"jdbc:sqlserver://192.168.1.106:1433;", + "id":"sa", + "pw":"qwe123", + "query" : "select * from master.dbo.sysprocesses" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"health_activedirectory", + "container":"network_proxy" + }, + "items" : [ + { + "keys" : [ + { + "metric" : "object[$0].db[$1].datafile_size", + "key" : "Data File(s) Size (KB)" + }, + { + "metric" : "object[$0].db[$1].logfile_size", + "key" : "Log File(s) Size (KB)" + } + ], + "queryInfo" : { + "query": "select object_name,instance_name, counter_name, cntr_value from sys.dm_os_performance_counters where ( counter_name = 'Data File(s) Size (KB)' or counter_name = 'Log File(s) Size (KB)' ) AND object_name = 'SQLServer:Databases'", + "extend" : { + "test":"test" + } + }, + "mappingInfo" : { + "parseDirection" : "row", + "arrayColumns" : [ "object_name","instance_name"], + "keyColumns" : ["counter_name"], + "valueColumn" : "cntr_value" + } + } + ] +} \ No newline at end of file