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" "encoding/json"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go" "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" "testing"
"time" "loafle.com/overflow/crawler_go/config"
) )
func setConfig() crawler.Crawler { func setConfig() crawler.Crawler {
r := NewRedisHeahthCrawler() r := NewRedisHeahthCrawler()
m := make(map[string]interface{}, 0) m := config.Config{}
m.Target = config.Target{}
m["ip"] = "192.168.1.104" m.Target.Connection = config.Connection{}
m["port"] = "6379" m.Target.Connection.Ip = "192.168.1.104"
m["portType"] = "tcp" m.Target.Connection.Port = "6379"
m["ssl"] = false m.Target.Connection.PortType = "tcp"
m.Target.Connection.SSL = false
r.PutConfig("redis", m) r.PutConfig("redis", m)
@ -31,42 +28,41 @@ func setConfig() crawler.Crawler {
func TestMatch(t *testing.T) { func TestMatch(t *testing.T) {
// test config // test config
r := setConfig() r := setConfig()
out := param.Output{} b, _ := r.Get("redis")
r.Get("redis", &out)
var check bool var check bool
json.Unmarshal(out.Data, &check) json.Unmarshal(b, &check)
assert.Equal(t, true, check) assert.Equal(t, true, check)
} }
//
func start() { //func start() {
r := setConfig() // r := setConfig()
//
of_rpc.AddDelegate("redis", r) // of_rpc.AddDelegate("redis", r)
err := of_rpc.StartJSONRPC() // err := of_rpc.StartJSONRPC()
if err != nil { // if err != nil {
log.Fatal(err) // log.Fatal(err)
} // }
} //}
//
func TestRPC(t *testing.T) { //func TestRPC(t *testing.T) {
go start() // go start()
time.Sleep(2 * time.Second) // time.Sleep(2 * time.Second)
//
in := param.Input{ // in := param.Input{
Name: "redis", // Name: "redis",
Id: "redis", // Id: "redis",
} // }
//
result, err := client.InvokeJSONRPCGet("50000", in) // result, err := client.InvokeJSONRPCGet("50000", in)
//
if err != nil { // if err != nil {
t.Fatal(err) // t.Fatal(err)
} // }
//
var check bool // var check bool
json.Unmarshal(result.Data, &check) // json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check) // assert.Equal(t, true, check)
} //}

View File

@ -12,7 +12,7 @@ import (
func initConfig() crawler.CrawlerImpl{ func initConfig() crawler.CrawlerImpl{
c := crawler.CrawlerImpl{} c := crawler.CrawlerImpl{}
c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler()) c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler())
c.Init("/root/gowork/src/loafle.com/overflow/crawler_go/config/") c.Init("./")
return c 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" : [
]
}