61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
|
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")
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|