This commit is contained in:
jackdaw@loafle.com 2017-04-14 17:31:12 +09:00
parent 3283a7f558
commit eb2c18b44c
3 changed files with 66 additions and 47 deletions

View File

@ -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)
//}

View File

@ -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
}

23
test/example.json Normal file
View File

@ -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" : [
]
}