From eb2c18b44c3803d239347434c650575e43c7d1c0 Mon Sep 17 00:00:00 2001 From: "jackdaw@loafle.com" Date: Fri, 14 Apr 2017 17:31:12 +0900 Subject: [PATCH] . --- .../redis_protocol_test.go | 88 +++++++++---------- test/crawler_test.go | 2 +- test/example.json | 23 +++++ 3 files changed, 66 insertions(+), 47 deletions(-) create mode 100644 test/example.json diff --git a/health_crawler/redis_protocol_crawler_go/redis_protocol_test.go b/health_crawler/redis_protocol_crawler_go/redis_protocol_test.go index d346b6a..9ebb15b 100644 --- a/health_crawler/redis_protocol_crawler_go/redis_protocol_test.go +++ b/health_crawler/redis_protocol_crawler_go/redis_protocol_test.go @@ -4,24 +4,21 @@ import ( "encoding/json" "github.com/stretchr/testify/assert" "loafle.com/overflow/crawler_go" - "loafle.com/overflow/of_rpc_go" - "loafle.com/overflow/of_rpc_go/client" - "loafle.com/overflow/of_rpc_go/models/param" - "log" "testing" - "time" + "loafle.com/overflow/crawler_go/config" ) func setConfig() crawler.Crawler { r := NewRedisHeahthCrawler() - - m := make(map[string]interface{}, 0) - - m["ip"] = "192.168.1.104" - m["port"] = "6379" - m["portType"] = "tcp" - m["ssl"] = false + + m := config.Config{} + m.Target = config.Target{} + m.Target.Connection = config.Connection{} + m.Target.Connection.Ip = "192.168.1.104" + m.Target.Connection.Port = "6379" + m.Target.Connection.PortType = "tcp" + m.Target.Connection.SSL = false r.PutConfig("redis", m) @@ -31,42 +28,41 @@ func setConfig() crawler.Crawler { func TestMatch(t *testing.T) { // test config r := setConfig() - - out := param.Output{} - r.Get("redis", &out) + + b, _ := r.Get("redis") var check bool - json.Unmarshal(out.Data, &check) + json.Unmarshal(b, &check) assert.Equal(t, true, check) } - -func start() { - r := setConfig() - - of_rpc.AddDelegate("redis", r) - err := of_rpc.StartJSONRPC() - if err != nil { - log.Fatal(err) - } -} - -func TestRPC(t *testing.T) { - go start() - time.Sleep(2 * time.Second) - - in := param.Input{ - Name: "redis", - Id: "redis", - } - - result, err := client.InvokeJSONRPCGet("50000", in) - - if err != nil { - t.Fatal(err) - } - - var check bool - json.Unmarshal(result.Data, &check) - assert.Equal(t, true, check) -} +// +//func start() { +// r := setConfig() +// +// of_rpc.AddDelegate("redis", r) +// err := of_rpc.StartJSONRPC() +// if err != nil { +// log.Fatal(err) +// } +//} +// +//func TestRPC(t *testing.T) { +// go start() +// time.Sleep(2 * time.Second) +// +// in := param.Input{ +// Name: "redis", +// Id: "redis", +// } +// +// result, err := client.InvokeJSONRPCGet("50000", in) +// +// if err != nil { +// t.Fatal(err) +// } +// +// var check bool +// json.Unmarshal(result.Data, &check) +// assert.Equal(t, true, check) +//} diff --git a/test/crawler_test.go b/test/crawler_test.go index d60d049..fcd650e 100644 --- a/test/crawler_test.go +++ b/test/crawler_test.go @@ -12,7 +12,7 @@ import ( func initConfig() crawler.CrawlerImpl{ c := crawler.CrawlerImpl{} c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler()) - c.Init("/root/gowork/src/loafle.com/overflow/crawler_go/config/") + c.Init("./") return c } diff --git a/test/example.json b/test/example.json new file mode 100644 index 0000000..3cf0a7c --- /dev/null +++ b/test/example.json @@ -0,0 +1,23 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.104", + "port" : "6379", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"redis_protocol_crawler", + "container":"network_crawler" + }, + "items" : [ + ] +} \ No newline at end of file