Merge branch 'EDGE-301' into EDGE-299
[platform/core/system/edge-orchestration.git] / src / orchestrationapi / orchestration_api_test.go
1 package orchestrationapi
2
3
4 import (
5   "testing"
6   "time"
7   "os/exec"
8   "fmt"
9
10   configuremgr     "configuremgr"
11   confdescription  "configuremgr/description"
12
13   // mockconfiguremgr "configuremgr/mock"
14
15   scoringmgr       "scoringmgr"
16   mockscoringmgr   "scoringmgr/mock"
17   
18   // discoverymgr     "discoverymgr"
19   // servicemgr       "servicemgr"
20
21 )
22
23
24 //jaehoon.hyun , jaehoon.hyun
25 func TestConfigureMgrScoringMgr(t *testing.T){
26
27   //make orche
28   orcheMock := new(Orche)
29
30   orcheMock.IScoringmgr    = scoringmgr.Init()
31   orcheMock.IConfiguremgr  = configuremgr.Init()
32
33   orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringAddInterface
34   orcheMock.IScoringmgr.IGetScore     = mockscoringmgr.GetScoreRandom100Mock
35   orcheMock.IScoringmgr.Ch            = make(chan interface{}, 1024)
36
37   orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath  = pushConfPathDiscoveryDeviceMock
38   orcheMock.IConfiguremgr.IScoringMgr.PushLibPath     = scoringmgr.PushLibPath
39   orcheMock.IConfiguremgr.IScoringMgr.Ch              = orcheMock.IScoringmgr.Ch
40
41   orcheMock.IDiscoverymgr.GetEndpointDevices = getEndpointDevicesMock
42   orcheMock.IServicemgr.ExecuteApp           = executeAppMock
43
44
45   //start module function
46   orcheMock.IScoringmgr.Listening()
47   go orcheMock.IConfiguremgr.Watch("/tmp/foo")
48   
49   //init scenario
50   execCommand("rm -rf /tmp/foo/mysum")
51   time.Sleep(time.Duration(1) * time.Second)
52
53   //user scenario
54   execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo"))
55   time.Sleep(time.Duration(5) * time.Second)
56
57
58   orcheMock.IScoringmgr.RemoveLib("/tmp/foo/mysum/libmysum.so")
59
60   orcheMock.IConfiguremgr.Done <- true
61
62 }
63
64 //jaehoon.hyun, damon92-lee
65 func TestConfigureMgrDiscoveryMgr(t *testing.T) {
66
67 }
68
69 //jaehoon.hyun, chacha
70 func TestRequestServiceFunctionServiceMgr(t *testing.T){
71
72   //make orche
73   // orcheMock := new(Orche)
74
75   // orcheMock.IScoringmgr    = scoringmgr.Init()
76   // orcheMock.IConfiguremgr  = configuremgr.Init()
77
78   // orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringAddInterface
79   // orcheMock.IScoringmgr.IGetScore     = mockscoringmgr.GetScoreRandom100Mock
80   // orcheMock.IScoringmgr.Ch            = make(chan interface{}, 1024)
81
82   // orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath  = pushConfPathDiscoveryDeviceMock
83   // orcheMock.IConfiguremgr.IScoringMgr.PushLibPath     = scoringmgr.PushLibPath
84   // orcheMock.IConfiguremgr.IScoringMgr.Ch              = orcheMock.IScoringmgr.Ch
85
86   // orcheMock.IDiscoverymgr.GetEndpointDevices = getEndpointDevicesMock
87   // orcheMock.IServicemgr.ExecuteApp           = executeAppMock
88
89
90   // //scoringmgr init
91   // orcheMock.IScoringmgr.Listening()
92
93   // //configuremgr init
94   // go orcheMock.IConfiguremgr.Watch("/tmp/foo")
95
96   // //servicemgr init
97   // servicemgr.InitServiceMap()
98
99   // //user scenario
100   // RequestService("mysum", "ls", []string{"-al"})
101
102 }
103
104 //daemon92-lee, chacha
105 func TestDiscoveryMgrServiceMgr(t *testing.T){
106
107
108 }
109
110 //jaehoon.hyun, daemon92-lee, jaehoon.hyun
111 func TestConfigureMgrDiscoveryMgrScoringMgr(t *testing.T){
112
113 }
114
115 //jaehoon.hyun, daemon92-lee, chacha
116 func TestConfigureMgrDiscoveryMgrServiceMgr(t *testing.T){
117
118
119 }
120
121 //jaehoon.hyun, chacha, jaehoon.hyun
122 func TestConfigureMgrServiceMgrScoringMgr(t *testing.T){
123
124 }
125
126 //jaehoon.hyun, daemon92-lee, chacha, jaehoon.hyun
127 func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T){
128
129
130 }
131
132
133 func pushConfPathDiscoveryDeviceMock (doc *confdescription.Doc) (err error) {
134   ILog.Println("pushConfPathDiscoveryDeviceMock")
135   ILog.Println(*doc)
136   return
137 }
138
139 func pushLibPathScoringAppMock(libPath string, doc *confdescription.Doc, handlersCh chan<- interface{}) (err error) {
140   ILog.Println("pushLibPathScoringAppMock")
141   ILog.Println(libPath)
142   return
143 }
144
145 func getEndpointDevicesMock(serviceName string) []string {
146   return []string{"localhost", "localhost"}
147 }
148
149 func executeAppMock(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error) {
150   ILog.Println("ExecuteApp")
151   ILog.Println(target)
152   ILog.Println(name)
153   ILog.Println(args)
154   return
155 }
156
157
158 func execCommand(command string) {
159   configuremgr.DLog.Println(command)
160   cmd := exec.Command("sh", "-c", command)
161   stdoutStderr, err := cmd.CombinedOutput()
162   configuremgr.DLog.Printf("%s", stdoutStderr)
163   if err != nil {
164     configuremgr.ELog.Fatal(err)
165   }
166 }