26eead5021
address
98 lines
1.5 KiB
Go
98 lines
1.5 KiB
Go
package test
|
|
|
|
import (
|
|
"testing"
|
|
"github.com/stretchr/testify/assert"
|
|
"encoding/json"
|
|
"git.loafle.net/overflow/crawler_go/health_crawler/redis_protocol_crawler_go"
|
|
"git.loafle.net/overflow/crawler_go"
|
|
|
|
"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))
|
|
|
|
}
|