added crawler

This commit is contained in:
snoop
2017-08-04 11:27:37 +09:00
parent 4b2ea88929
commit 7ec9a326fd
59 changed files with 6399 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
package test
import (
"encoding/json"
"git.loafle.net/overflow/overflow_probe/crawler"
"git.loafle.net/overflow/overflow_probe/crawler/health_crawler/redis_protocol_crawler_go"
"github.com/stretchr/testify/assert"
"testing"
"io/ioutil"
)
func initConfig() crawler.CrawlerImpl {
c := crawler.CrawlerImpl{}
c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler())
b, _ := ioutil.ReadFile("./example.json")
c.Init(b)
return c
}
func TestCrawlerInit(t *testing.T) {
c := initConfig()
m := c.GetConfig("test_id_001")
assert.Equal(t, m.Id, "test_id_001")
}
func TestCrawlerAdd(t *testing.T) {
c := initConfig()
c.Remove("test_id_001")
bb, _ := ioutil.ReadFile("./example.json")
b, _ := c.Add(bb)
var ck bool
json.Unmarshal(b, &ck)
assert.Equal(t, true, ck)
}
func TestCrawlerRemove(t *testing.T) {
c := initConfig()
b, _ := c.Remove("test_id_001")
var ck bool
json.Unmarshal(b, &ck)
assert.Equal(t, true, ck)
}
func TestCrawlerGet(t *testing.T) {
c := initConfig()
b, _ := c.Get("test_id_001")
var ck bool
json.Unmarshal(b, &ck)
assert.Equal(t, true, ck)
}
func TestFolder(t *testing.T) {
configPath := "./"
files, err := ioutil.ReadDir(configPath)
if err != nil {
t.Log(err)
}
for _, file := range files {
if file.IsDir() == true {
continue
}
t.Log(file.Name())
//_,err := c.Add(file.Name())
if err != nil {
t.Log(err)
}
}
}
func TestFile(t *testing.T) {
b, _ := ioutil.ReadFile("./example.json")
t.Log(string(b))
}

28
crawler/test/example.json Normal file
View File

@@ -0,0 +1,28 @@
{
"id" : "test_id_001",
"target" : {
"connection" : {
"ip" : "192.168.1.104",
"port" : "6379",
"ssl" : false,
"portType" : "tcp"
},
"auth" : {
}
},
"schedule" : {
"interval" : "10"
},
"crawler" : {
"name":"redis_crawler",
"container":"java_proxy"
},
"items" : [
{
"type":"cpu",
"":[],
"":[],
}
]
}