2017-04-13 07:09:16 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"encoding/json"
|
2017-05-29 11:05:49 +00:00
|
|
|
"git.loafle.net/overflow/crawler_go/health_crawler/redis_protocol_crawler_go"
|
|
|
|
"git.loafle.net/overflow/crawler_go"
|
2017-04-27 10:42:46 +00:00
|
|
|
|
|
|
|
"io/ioutil"
|
2017-04-13 07:09:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func initConfig() crawler.CrawlerImpl{
|
|
|
|
c := crawler.CrawlerImpl{}
|
|
|
|
c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler())
|
2017-04-27 10:42:46 +00:00
|
|
|
|
|
|
|
b, _ := ioutil.ReadFile("./example.json")
|
|
|
|
|
|
|
|
c.Init(b)
|
2017-04-13 07:09:16 +00:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCrawlerInit(t *testing.T) {
|
|
|
|
|
|
|
|
c := initConfig()
|
2017-04-27 10:42:46 +00:00
|
|
|
m := c.GetConfig("test_id_001")
|
|
|
|
assert.Equal(t, m.Id , "test_id_001")
|
2017-04-13 07:09:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCrawlerAdd(t *testing.T) {
|
|
|
|
|
|
|
|
c := initConfig()
|
2017-04-27 10:42:46 +00:00
|
|
|
c.Remove("test_id_001")
|
|
|
|
bb, _ := ioutil.ReadFile("./example.json")
|
|
|
|
b , _ := c.Add(bb)
|
|
|
|
|
2017-04-13 07:09:16 +00:00
|
|
|
var ck bool
|
|
|
|
json.Unmarshal(b,&ck)
|
2017-04-27 10:42:46 +00:00
|
|
|
|
2017-04-13 07:09:16 +00:00
|
|
|
assert.Equal(t,true,ck)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCrawlerRemove(t *testing.T) {
|
|
|
|
c := initConfig()
|
2017-04-27 10:42:46 +00:00
|
|
|
b, _ := c.Remove("test_id_001")
|
2017-04-13 07:09:16 +00:00
|
|
|
|
|
|
|
var ck bool
|
|
|
|
json.Unmarshal(b,&ck)
|
|
|
|
|
|
|
|
assert.Equal(t,true,ck)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCrawlerGet(t *testing.T) {
|
|
|
|
c := initConfig()
|
2017-04-27 10:42:46 +00:00
|
|
|
b, _ := c.Get("test_id_001")
|
2017-04-13 07:09:16 +00:00
|
|
|
|
|
|
|
var ck bool
|
|
|
|
json.Unmarshal(b,&ck)
|
|
|
|
|
|
|
|
assert.Equal(t,true,ck)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-27 10:42:46 +00:00
|
|
|
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))
|
|
|
|
|
|
|
|
}
|