config_manager_go/config_manager_test.go
jackdaw@loafle.com 297afd4dc1 remodeling
2017-04-27 20:34:07 +09:00

79 lines
2.1 KiB
Go

package config_manager_go
import (
"testing"
"github.com/stretchr/testify/assert"
"io/ioutil"
"log"
"loafle.com/overflow/agent_api/config_manager"
"encoding/json"
"github.com/google/uuid"
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/observer/messages"
"time"
)
func TestLoadConfig(t *testing.T) {
// notify temp channel
ch := make(chan interface{},0)
observer.Add(messages.CONFIGMANAGER_LOADED,ch)
go func() {
data :=<- ch
c := data.(config_manager.ConfigManager)
cc := c.GetCrawlers()
//ccc := cc["75045c53-a78d-4589-b8c1-4482cab720b6"]
//
//mmmm := ccc.Items[0].Keys[0].Metric
//
//fmt.Println(mmmm)
//
assert.NotEqual(t, len(cc),0)
}()
// make config manager after to load
c := NewConfigManager()
c.loadGlobalConfig("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml")
c.loadCrawlerConfigAll()
assert.NotEqual(t, len(c.configs),0)
observer.Notify(messages.CONFIGMANAGER_LOADED,c)
time.Sleep(2 * time.Second)
}
func TestAddConfig(t *testing.T) {
_configManager.loadGlobalConfig("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml")
// 원본 테스트 설정 파일 로드
b, err := ioutil.ReadFile("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/test.json")
if err != nil {
log.Panic(err)
}
var m = config_manager.Config{}
json.Unmarshal(b, &m)
// uuid로 원본 파일 복제
rid,_ := uuid.NewRandom()
m.Id = rid.String()
b,err = json.Marshal(&m)
ioutil.WriteFile("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/" + m.Id,b,0644)
// add test
observer.Notify(messages.ADD_SENSOR_0,"/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/" + m.Id)
time.Sleep(1 * time.Second)
}
func TestRemoveConfig(t *testing.T) {
_configManager.loadGlobalConfig("/root/gowork/src/loafle.com/overflow/config_manager_go/test_agent/global.yaml")
_configManager.loadCrawlerConfigAll()
// remove test
observer.Notify(messages.REMOVE_SENSOR_0,"289575d2-4a34-4475-b91d-7fb0992cc3de")
time.Sleep(1 * time.Second)
}