* limitations under the License.
*
*******************************************************************************/
+
+/*
+**************** HOW TO USE ********************
+$ source workspaceProfile.sh
+$ go test -failfast -v -count=1 orchestrationapi
+************************************************
+*/
package orchestrationapi
import (
configuremgr "configuremgr"
confdescription "configuremgr/description"
+ errormsg "errormsg"
// mockconfiguremgr "configuremgr/mock"
+
discoverymgr "discoverymgr"
scoringmgr "scoringmgr"
mockscoringmgr "scoringmgr/mock"
var logPrefixTest = "[orchestrationapi test]"
-//jaehoon.hyun , jaehoon.hyun
-func TestConfigureMgrScoringMgrAlreadyScoring2Library(t *testing.T) {
-
+func TestPreCondition(t *testing.T) {
//init scenario
+ //TODO : Need wifi off logic.
listeningDir := "/tmp/foo"
execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
- execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring2/", listeningDir))
time.Sleep(time.Duration(100) * time.Millisecond)
- //make orche
orcheMock := Init("")
- //create modules
orcheMock.IScoringmgr = scoringmgr.Init()
orcheMock.IConfiguremgr = configuremgr.Init()
- //scoringmgr interface
orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService
orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
- orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
+ orcheMock.IScoringmgr.IGetScore = scoringmgr.GetScore
orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
- //configuremgr interface
- orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock
+
+ orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = discoverymgr.AddNewServiceName
orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
- //discoverymgr interface
- orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock
+ orcheMock.IDiscoverymgr.GetEndpointDevices = discoverymgr.GetDeviceListWithService
+ orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
- //servicemgr interface
- orcheMock.IServicemgr.ExecuteApp = ExecuteAppMock
+ //discoverymgr init
+ discoverymgr.InitDiscovery()
- //start scoringmgr
+ //servicemgr init
+ servicemgr.Init()
+
+ //scoringmgr init
orcheMock.IScoringmgr.Listening()
orcheMock.IScoringmgr.IStartResourceService()
- //start configuremgr
+ //securemgr init
+ securemgr.Init("../securemgr/test/key.txt")
+
+ //configuremgr init
go orcheMock.IConfiguremgr.Watch(listeningDir)
orcheMock.Ready = true
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
- time.Sleep(time.Duration(300) * time.Millisecond)
+ time.Sleep(time.Duration(100) * time.Millisecond)
+ ret := RequestService("ls", []string{"-al"})
+
+ switch ret {
+ case -2:
+ case -3:
+ t.Fatal(errormsg.ToString(ret))
+ break
+ default:
+ log.Println(logPrefixTest, "REEEEEEEEETTTTTTTTT == ", ret)
+ break
+ }
+
+ time.Sleep(time.Duration(100) * time.Millisecond)
//release scoringmgr
orcheMock.IScoringmgr.IStopResourceService()
orcheMock.IScoringmgr.RemoveAll()
- time.Sleep(time.Duration(100) * time.Millisecond)
//release configuremgr
orcheMock.IConfiguremgr.Done <- true
- //waiting resource thread stop
- time.Sleep(time.Duration(100) * time.Millisecond)
+ //release discoverymgr
+ discoverymgr.ExitChan <- 1
+ if discoverymgr.IsNilServer() == true {
+ discoverymgr.ExitPollingOutBoundCh <- 1
+ }
+ time.Sleep(time.Duration(100) * time.Millisecond)
}
-//jaehoon.hyun, chacha, jaehoon.hyun
-func TestConfigureMgrServiceMgrScoringMgr(t *testing.T) {
+//jaehoon.hyun, damon92-lee
+func TestConfigureMgrDiscoveryMgr(t *testing.T) {
//init scenario
listeningDir := "/tmp/foo"
execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
- orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock
+ orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = discoverymgr.AddNewServiceName
orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
- orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock
- orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
-
- //servicemgr init
- servicemgr.Init()
+ orcheMock.IDiscoverymgr.GetEndpointDevices = discoverymgr.GetDeviceListWithService
+ orcheMock.IServicemgr.ExecuteApp = ExecuteAppMock
- // securemgr init
- securemgr.Init("../securemgr/test/key.txt")
+ //discoverymgr init
+ discoverymgr.InitDiscovery()
//scoringmgr init
orcheMock.IScoringmgr.Listening()
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
- RequestService("ls", []string{"-al"})
+ time.Sleep(time.Duration(3) * time.Second)
+ if ret := RequestService("ls", []string{"-al"}); ret < 0 {
+ t.Fatal(errormsg.ToString(ret))
+ }
time.Sleep(time.Duration(3) * time.Second)
//release scoringmgr
orcheMock.IScoringmgr.IStopResourceService()
orcheMock.IScoringmgr.RemoveAll()
- //release configuremgr
+ //release configure
orcheMock.IConfiguremgr.Done <- true
- time.Sleep(time.Duration(100) * time.Millisecond)
+ //release discoverymgr
+ discoverymgr.ExitChan <- 1
+ if discoverymgr.IsNilServer() == true {
+ discoverymgr.ExitPollingOutBoundCh <- 1
+ }
+
+ //waiting resource thread stop
+ time.Sleep(time.Duration(1000) * time.Millisecond)
}
//jaehoon.hyun , jaehoon.hyun
-func TestConfigureMgrScoringMgr(t *testing.T) {
+func TestConfigureMgrScoringMgrAlreadyScoring2Library(t *testing.T) {
+
//init scenario
listeningDir := "/tmp/foo"
execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
+ execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring2/", listeningDir))
time.Sleep(time.Duration(100) * time.Millisecond)
//make orche
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
- time.Sleep(time.Duration(3) * time.Second)
+ time.Sleep(time.Duration(300) * time.Millisecond)
//release scoringmgr
orcheMock.IScoringmgr.IStopResourceService()
//waiting resource thread stop
time.Sleep(time.Duration(100) * time.Millisecond)
+
+}
+
+//jaehoon.hyun, chacha, jaehoon.hyun
+func TestConfigureMgrServiceMgrScoringMgr(t *testing.T) {
+ //init scenario
+ listeningDir := "/tmp/foo"
+ execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
+ execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ orcheMock := Init("")
+
+ orcheMock.IScoringmgr = scoringmgr.Init()
+ orcheMock.IConfiguremgr = configuremgr.Init()
+
+ orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+ orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService
+ orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
+ orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
+ orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
+
+ orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock
+ orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
+ orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
+
+ orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock
+ orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
+
+ //servicemgr init
+ servicemgr.Init()
+
+ // securemgr init
+ securemgr.Init("../securemgr/test/key.txt")
+
+ //scoringmgr init
+ orcheMock.IScoringmgr.Listening()
+ orcheMock.IScoringmgr.IStartResourceService()
+
+ //configuremgr init
+ go orcheMock.IConfiguremgr.Watch(listeningDir)
+
+ orcheMock.Ready = true
+
+ //user scenario
+ execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
+ if ret := RequestService("ls", []string{"-al"}); ret < 0 {
+ t.Fatalf(errormsg.ToString(ret))
+ }
+ time.Sleep(time.Duration(3) * time.Second)
+
+ //release scoringmgr
+ orcheMock.IScoringmgr.IStopResourceService()
+ orcheMock.IScoringmgr.RemoveAll()
+
+ //release configuremgr
+ orcheMock.IConfiguremgr.Done <- true
+
+ time.Sleep(time.Duration(100) * time.Millisecond)
}
//jaehoon.hyun , jaehoon.hyun
-func TestConfigureMgrScoringMgrMyscoring2(t *testing.T) {
+func TestConfigureMgrScoringMgr(t *testing.T) {
//init scenario
listeningDir := "/tmp/foo"
execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
orcheMock.Ready = true
//user scenario
- execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring2/", listeningDir))
+ execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
time.Sleep(time.Duration(3) * time.Second)
//release scoringmgr
//waiting resource thread stop
time.Sleep(time.Duration(100) * time.Millisecond)
-
}
-func TestConfigureMgrScoringMgrMyScoringLib(t *testing.T) {
+//jaehoon.hyun , jaehoon.hyun
+func TestConfigureMgrScoringMgrMyscoring2(t *testing.T) {
//init scenario
listeningDir := "/tmp/foo"
execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
time.Sleep(time.Duration(100) * time.Millisecond)
//make orche
- orcheMock := new(Orche)
+ orcheMock := Init("")
//create modules
orcheMock.IScoringmgr = scoringmgr.Init()
orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
-
//configuremgr interface
orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock
orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
orcheMock.Ready = true
//user scenario
- execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
+ execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring2/", listeningDir))
time.Sleep(time.Duration(3) * time.Second)
//release scoringmgr
//waiting resource thread stop
time.Sleep(time.Duration(100) * time.Millisecond)
+
}
-//jaehoon.hyun, damon92-lee
-func TestConfigureMgrDiscoveryMgr(t *testing.T) {
+func TestConfigureMgrScoringMgrMyScoringLib(t *testing.T) {
//init scenario
listeningDir := "/tmp/foo"
execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
time.Sleep(time.Duration(100) * time.Millisecond)
- orcheMock := Init("")
+ //make orche
+ orcheMock := new(Orche)
+ //create modules
orcheMock.IScoringmgr = scoringmgr.Init()
orcheMock.IConfiguremgr = configuremgr.Init()
+ //scoringmgr interface
orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService
orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
- orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = discoverymgr.AddNewServiceName
+ //configuremgr interface
+ orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock
orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
- orcheMock.IDiscoverymgr.GetEndpointDevices = discoverymgr.GetDeviceListWithService
- orcheMock.IServicemgr.ExecuteApp = ExecuteAppMock
+ //discoverymgr interface
+ orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock
- //discoverymgr init
- discoverymgr.InitDiscovery()
+ //servicemgr interface
+ orcheMock.IServicemgr.ExecuteApp = ExecuteAppMock
- //scoringmgr init
+ //start scoringmgr
orcheMock.IScoringmgr.Listening()
orcheMock.IScoringmgr.IStartResourceService()
- //configuremgr init
+ //start configuremgr
go orcheMock.IConfiguremgr.Watch(listeningDir)
orcheMock.Ready = true
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
time.Sleep(time.Duration(3) * time.Second)
- RequestService("ls", []string{"-al"})
- time.Sleep(time.Duration(3) * time.Second)
//release scoringmgr
orcheMock.IScoringmgr.IStopResourceService()
orcheMock.IScoringmgr.RemoveAll()
+ time.Sleep(time.Duration(100) * time.Millisecond)
- //release configure
+ //release configuremgr
orcheMock.IConfiguremgr.Done <- true
- //release discoverymgr
- discoverymgr.ExitChan <- 1
- if discoverymgr.IsNilServer() == true {
- discoverymgr.ExitPollingOutBoundCh <- 1
- }
-
//waiting resource thread stop
- time.Sleep(time.Duration(1000) * time.Millisecond)
+ time.Sleep(time.Duration(100) * time.Millisecond)
}
//jaehoon.hyun, chacha
go func() {
ret := RequestService("ls", []string{"-al"})
if ret != -1 {
- t.Fatal("is it wifi on????? plz off and retry test")
+ t.Fatal("is it wifi on????? plz off and retry test ", ret)
} else {
- log.Println(logPrefixTest, "REEEEEEEEETTTTTTTTT == -1")
+ log.Println(logPrefixTest, "REEEEEEEEETTTTTTTTT == ", ret)
}
time.Sleep(time.Duration(100) * time.Millisecond)
time.Sleep(time.Duration(100) * time.Millisecond)
}
-func TestTurnOffWifiErrorAtRequestServiceApi(t *testing.T) {
- //init scenario
- //TODO : Need wifi off logic.
- turnOffWifi()
- listeningDir := "/tmp/foo"
- execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
- execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
- time.Sleep(time.Duration(100) * time.Millisecond)
-
- orcheMock := Init("")
-
- orcheMock.IScoringmgr = scoringmgr.Init()
- orcheMock.IConfiguremgr = configuremgr.Init()
-
- orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
- orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService
- orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
- orcheMock.IScoringmgr.IGetScore = scoringmgr.GetScore
- orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
-
- orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = discoverymgr.AddNewServiceName
- orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
- orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
-
- orcheMock.IDiscoverymgr.GetEndpointDevices = discoverymgr.GetDeviceListWithService
- orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
-
- //discoverymgr init
- discoverymgr.InitDiscovery()
-
- //servicemgr init
- servicemgr.Init()
-
- //scoringmgr init
- orcheMock.IScoringmgr.Listening()
- orcheMock.IScoringmgr.IStartResourceService()
-
- //securemgr init
- securemgr.Init("../securemgr/test/key.txt")
-
- //configuremgr init
- go orcheMock.IConfiguremgr.Watch(listeningDir)
-
- orcheMock.Ready = true
-
- //user scenario
- execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
- time.Sleep(time.Duration(100) * time.Millisecond)
- ret := RequestService("ls", []string{"-al"})
- if ret != -2 {
- t.Fatal("is it wifi on????? plz off and retry test ", ret)
- } else {
- log.Println(logPrefixTest, "REEEEEEEEETTTTTTTTT == ", ret)
- }
-
- time.Sleep(time.Duration(100) * time.Millisecond)
-
- //release scoringmgr
- orcheMock.IScoringmgr.IStopResourceService()
- orcheMock.IScoringmgr.RemoveAll()
-
- //release configuremgr
- orcheMock.IConfiguremgr.Done <- true
-
- //release discoverymgr
- discoverymgr.ExitChan <- 1
- if discoverymgr.IsNilServer() == true {
- discoverymgr.ExitPollingOutBoundCh <- 1
- }
-
- //turnOn wifi
- turnOnWifi()
-
- time.Sleep(time.Duration(100) * time.Millisecond)
-}
-
+//=============== ORCHE MOCK =======================
func PushConfPathDiscoveryDeviceMock(doc *confdescription.Doc) (err error) {
log.Println("[orchestrationapi] pushConfPathDiscoveryDeviceMock")
log.Println(*doc)
return
}
+//=============== ORCHE MOCK =======================
+
func execCommand(command string) {
log.Println(command)
cmd := exec.Command("sh", "-c", command)