1 package orchestrationapi
10 configuremgr "configuremgr"
11 confdescription "configuremgr/description"
13 // mockconfiguremgr "configuremgr/mock"
15 scoringmgr "scoringmgr"
16 mockscoringmgr "scoringmgr/mock"
18 // discoverymgr "discoverymgr"
19 servicemgr "servicemgr"
24 //jaehoon.hyun , jaehoon.hyun
25 func TestConfigureMgrScoringMgr(t *testing.T){
28 orcheMock := new(Orche)
30 orcheMock.IScoringmgr = scoringmgr.Init()
31 orcheMock.IConfiguremgr = configuremgr.Init()
33 orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringAddInterface
34 orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
35 orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
37 orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = pushConfPathDiscoveryDeviceMock
38 orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
39 orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
41 orcheMock.IDiscoverymgr.GetEndpointDevices = getEndpointDevicesMock
42 orcheMock.IServicemgr.ExecuteApp = executeAppMock
45 //start module function
46 orcheMock.IScoringmgr.Listening()
47 go orcheMock.IConfiguremgr.Watch("/tmp/foo")
50 execCommand("rm -rf /tmp/foo/mysum")
51 time.Sleep(time.Duration(1) * time.Second)
54 execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo"))
55 time.Sleep(time.Duration(3) * time.Second)
58 orcheMock.IScoringmgr.RemoveLib("mysum")
59 orcheMock.IConfiguremgr.Done <- true
63 //jaehoon.hyun, damon92-lee
64 func TestConfigureMgrDiscoveryMgr(t *testing.T) {
68 //jaehoon.hyun, chacha
69 func TestRequestServiceFunctionServiceMgr(t *testing.T){
73 orcheMock.IScoringmgr = scoringmgr.Init()
74 orcheMock.IConfiguremgr = configuremgr.Init()
76 orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringAddInterface
77 orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
78 orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
80 orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = pushConfPathDiscoveryDeviceMock
81 orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
82 orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
84 orcheMock.IDiscoverymgr.GetEndpointDevices = getEndpointDevicesMock
85 orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
89 orcheMock.IScoringmgr.Listening()
92 go orcheMock.IConfiguremgr.Watch("/tmp/foo")
95 servicemgr.InitServiceMap()
99 execCommand("rm -rf /tmp/foo/mysum")
100 time.Sleep(time.Duration(1) * time.Second)
103 execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo"))
104 time.Sleep(time.Duration(3) * time.Second)
105 RequestService("mysum", "ls", []string{"-al"})
109 time.Sleep(time.Duration(1) * time.Second)
110 orcheMock.IScoringmgr.RemoveLib("mysum")
111 orcheMock.IConfiguremgr.Done <- true
116 //daemon92-lee, chacha
117 func TestDiscoveryMgrServiceMgr(t *testing.T){
122 //jaehoon.hyun, daemon92-lee, jaehoon.hyun
123 func TestConfigureMgrDiscoveryMgrScoringMgr(t *testing.T){
127 //jaehoon.hyun, daemon92-lee, chacha
128 func TestConfigureMgrDiscoveryMgrServiceMgr(t *testing.T){
133 //jaehoon.hyun, chacha, jaehoon.hyun
134 func TestConfigureMgrServiceMgrScoringMgr(t *testing.T){
138 //jaehoon.hyun, daemon92-lee, chacha, jaehoon.hyun
139 func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T){
145 func pushConfPathDiscoveryDeviceMock (doc *confdescription.Doc) (err error) {
146 ILog.Println("pushConfPathDiscoveryDeviceMock")
151 func pushLibPathScoringAppMock(libPath string, doc *confdescription.Doc, handlersCh chan<- interface{}) (err error) {
152 ILog.Println("pushLibPathScoringAppMock")
153 ILog.Println(libPath)
157 func getEndpointDevicesMock(serviceName string) []string {
158 DLog.Printf("getEndpointDevicesMock serviceName: %s\n", serviceName)
159 return []string{"localhost", "localhost"}
162 func executeAppMock(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error) {
163 ILog.Println("ExecuteApp")
171 func execCommand(command string) {
172 configuremgr.DLog.Println(command)
173 cmd := exec.Command("sh", "-c", command)
174 stdoutStderr, err := cmd.CombinedOutput()
175 configuremgr.DLog.Printf("%s", stdoutStderr)
177 configuremgr.ELog.Fatal(err)