overflow_probe/config_manager/config_manager_test.go

69 lines
2.1 KiB
Go
Raw Normal View History

2017-08-04 02:32:31 +00:00
package config_manager
2017-08-03 10:08:34 +00:00
import (
"testing"
//"github.com/stretchr/testify/assert"
"encoding/json"
2017-08-04 02:32:31 +00:00
"git.loafle.net/overflow/overflow_probe/agent_api/config_manager"
"git.loafle.net/overflow/overflow_probe/agent_api/messages"
"git.loafle.net/overflow/overflow_probe/agent_api/observer"
2017-08-04 02:55:31 +00:00
log "github.com/cihub/seelog"
2017-08-03 10:08:34 +00:00
"github.com/google/uuid"
"io/ioutil"
"time"
)
func TestLoadConfig(t *testing.T) {
// notify temp channel
//ch := make(chan interface{},0)
//observer.Add(messages.CFG_LOADED,ch)
//go func() {
// data :=<- ch
// c := data.(config_manager.ConfigManager)
// cc := c.GetSensors()
// assert.NotEqual(t, len(cc),0)
//}()
// make config manager after to load
//c := NewConfigManager()
2017-08-04 02:32:31 +00:00
//c.loadGlobalConfig("/root/gowork/src/git.loafle.net/overflow/overflow_probe/config_manager/test_agent/global.yaml")
2017-08-03 10:08:34 +00:00
//c.loadCrawlerConfigAll()
//
//assert.NotEqual(t, len(c.configs),0)
//observer.Notify(messages.CFG_LOADED,c)
//time.Sleep(1 * time.Second)
}
func TestAddConfig(t *testing.T) {
2017-08-04 02:32:31 +00:00
_configManager.loadGlobalConfig("/root/gowork/src/git.loafle.net/overflow/overflow_probe/config_manager/test_agent/global.yaml")
2017-08-03 10:08:34 +00:00
// 원본 테스트 설정 파일 로드
2017-08-04 02:32:31 +00:00
b, err := ioutil.ReadFile("/root/gowork/src/git.loafle.net/overflow/overflow_probe/config_manager/test_agent/test.json")
2017-08-03 10:08:34 +00:00
if err != nil {
2017-08-04 02:55:31 +00:00
log.Error(err)
2017-08-03 10:08:34 +00:00
}
var m = config_manager.Config{}
json.Unmarshal(b, &m)
// uuid로 원본 파일 복제
rid, _ := uuid.NewRandom()
m.Id = rid.String()
b, err = json.Marshal(&m)
2017-08-04 02:32:31 +00:00
ioutil.WriteFile("/root/gowork/src/git.loafle.net/overflow/overflow_probe/config_manager/test_agent/"+m.Id, b, 0644)
2017-08-03 10:08:34 +00:00
// add test
2017-08-04 02:32:31 +00:00
observer.Notify(messages.TASK_SENSOR_ADD, "/root/gowork/src/git.loafle.net/overflow/overflow_probe/config_manager/test_agent/"+m.Id)
2017-08-03 10:08:34 +00:00
time.Sleep(1 * time.Second)
}
func TestRemoveConfig(t *testing.T) {
GetInstance()
2017-08-04 02:32:31 +00:00
_configManager.loadGlobalConfig("/home/snoop/develop/path/go/src/git.loafle.net/overflow/overflow_probe/config_manager/test_agent/global.yaml")
2017-08-03 10:08:34 +00:00
_configManager.loadCrawlerConfigAll()
// remove test
//observer.Notify(messages.TASK_SENSOR_REMOVE,"d0fcc7b1-43a7-4acd-a7bf-c9572a9d4c9e")
time.Sleep(1 * time.Second)
}