import (
"fmt"
"log"
+ "net"
"os/exec"
"testing"
"time"
//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(300) * time.Millisecond)
//configuremgr init
go orcheMock.IConfiguremgr.Watch(listeningDir)
+ orcheMock.Ready = true
+
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
RequestService("ls", []string{"-al"})
//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)
//start configuremgr
go orcheMock.IConfiguremgr.Watch(listeningDir)
+ orcheMock.Ready = true
+
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring2/", listeningDir))
time.Sleep(time.Duration(3) * time.Second)
//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)
//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(3) * time.Second)
//servicemgr init
servicemgr.Init()
+ orcheMock.Ready = true
+
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
time.Sleep(time.Duration(3) * time.Second)
//configuremgr init
go orcheMock.IConfiguremgr.Watch(listeningDir)
+ orcheMock.Ready = true
+
//user scenario
execCommand(fmt.Sprintf("cp -ar %s %s", "../scoringmgr/mock/myscoring/", listeningDir))
time.Sleep(time.Duration(300) * time.Millisecond)
//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(3) * time.Second)
//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)
orcheMock := Init("")
ExitTestChan := make(chan int, 2)
+ //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)
+
go func() {
- //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.IScoringmgr = scoringmgr.Init()
orcheMock.IConfiguremgr = configuremgr.Init()
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)
+}
+
func PushConfPathDiscoveryDeviceMock(doc *confdescription.Doc) (err error) {
log.Println("[orchestrationapi] pushConfPathDiscoveryDeviceMock")
log.Println(*doc)
log.Fatal(err)
}
}
+
+//=============== NETWORK INTERFACE CARD CONTROL =======================
+func turnOffWifi() {
+ log.Println("turn off wifi")
+ wlIfaces := findWifiIface()
+ log.Println(wlIfaces)
+
+ for _, wlIface := range wlIfaces {
+ execCommand(fmt.Sprintf("sudo ifconfig %s down", wlIface))
+ }
+
+}
+
+func turnOnWifi() {
+ log.Println("turn on wifi")
+
+ wlIfaces := findWifiIface()
+ log.Println(wlIfaces)
+
+ for _, wlIface := range wlIfaces {
+ execCommand(fmt.Sprintf("sudo ifconfig %s up", wlIface))
+ }
+
+}
+
+func findWifiIface() (wlIfaces []string) {
+ ifaces, _ := net.Interfaces()
+ for _, iface := range ifaces {
+ if iface.Name[0:2] == "wl" {
+ wlIfaces = append(wlIfaces, iface.Name)
+ }
+ }
+
+ return
+}
+
+func getNetworkInterfaceCard() {
+ execCommand(fmt.Sprintf("ifconfig"))
+}
+
+//=============== NETWORK INTERFACE CARD CONTROL =======================