Merge pull request #27 from RS7-EdgeComputing/EDGE-331
[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(3) * time.Second)
56
57   //resource release
58   orcheMock.IScoringmgr.RemoveLib("mysum")
59   orcheMock.IConfiguremgr.Done <- true
60
61 }
62
63 //jaehoon.hyun, damon92-lee
64 func TestConfigureMgrDiscoveryMgr(t *testing.T) {
65
66 }
67
68 //jaehoon.hyun, chacha
69 func TestRequestServiceFunctionServiceMgr(t *testing.T){
70
71   orcheMock := Init("")
72
73   orcheMock.IScoringmgr    = scoringmgr.Init()
74   orcheMock.IConfiguremgr  = configuremgr.Init()
75
76   orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringAddInterface
77   orcheMock.IScoringmgr.IGetScore     = mockscoringmgr.GetScoreRandom100Mock
78   orcheMock.IScoringmgr.Ch            = make(chan interface{}, 1024)
79
80   orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath  = pushConfPathDiscoveryDeviceMock
81   orcheMock.IConfiguremgr.IScoringMgr.PushLibPath     = scoringmgr.PushLibPath
82   orcheMock.IConfiguremgr.IScoringMgr.Ch              = orcheMock.IScoringmgr.Ch
83
84   orcheMock.IDiscoverymgr.GetEndpointDevices = getEndpointDevicesMock
85   orcheMock.IServicemgr.ExecuteApp           = servicemgr.ExecuteApp
86
87
88   //scoringmgr init
89   orcheMock.IScoringmgr.Listening()
90
91   //configuremgr init
92   go orcheMock.IConfiguremgr.Watch("/tmp/foo")
93
94   //servicemgr init
95   servicemgr.InitServiceMap()
96
97   
98   //init scenario
99   execCommand("rm -rf /tmp/foo/mysum")
100   time.Sleep(time.Duration(1) * time.Second)
101
102   //user scenario
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"})
106
107
108   //resource release
109   time.Sleep(time.Duration(1) * time.Second)
110   orcheMock.IScoringmgr.RemoveLib("mysum")
111   orcheMock.IConfiguremgr.Done <- true
112
113   for {}
114 }
115
116 //daemon92-lee, chacha
117 func TestDiscoveryMgrServiceMgr(t *testing.T){
118
119
120 }
121
122 //jaehoon.hyun, daemon92-lee, jaehoon.hyun
123 func TestConfigureMgrDiscoveryMgrScoringMgr(t *testing.T){
124
125 }
126
127 //jaehoon.hyun, daemon92-lee, chacha
128 func TestConfigureMgrDiscoveryMgrServiceMgr(t *testing.T){
129
130
131 }
132
133 //jaehoon.hyun, chacha, jaehoon.hyun
134 func TestConfigureMgrServiceMgrScoringMgr(t *testing.T){
135
136 }
137
138 //jaehoon.hyun, daemon92-lee, chacha, jaehoon.hyun
139 func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T){
140
141
142 }
143
144
145 func pushConfPathDiscoveryDeviceMock (doc *confdescription.Doc) (err error) {
146   ILog.Println("pushConfPathDiscoveryDeviceMock")
147   ILog.Println(*doc)
148   return
149 }
150
151 func pushLibPathScoringAppMock(libPath string, doc *confdescription.Doc, handlersCh chan<- interface{}) (err error) {
152   ILog.Println("pushLibPathScoringAppMock")
153   ILog.Println(libPath)
154   return
155 }
156
157 func getEndpointDevicesMock(serviceName string) []string {
158   DLog.Printf("getEndpointDevicesMock serviceName: %s\n", serviceName)
159   return []string{"localhost", "localhost"}
160 }
161
162 func executeAppMock(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error) {
163   ILog.Println("ExecuteApp")
164   ILog.Println(target)
165   ILog.Println(name)
166   ILog.Println(args)
167   return
168 }
169
170
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)
176   if err != nil {
177     configuremgr.ELog.Fatal(err)
178   }
179 }