1 package servicemgr_test
14 servicemgr "servicemgr"
18 targetRemoteDeviceAddr = "127.0.0.1"
19 targetLocalAddr, _ = common.GetOutboundIP()
23 var keyFilePath string = "./../securemgr/test/key.txt"
27 securemgr.Init(keyFilePath)
30 func TestExecuteApp(t *testing.T) {
31 notiChan := make(chan string)
33 _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, nil, notiChan)
36 time.Sleep(time.Millisecond * 10)
39 func TestExecuteAppWithArgs(t *testing.T) {
40 notiChan := make(chan string)
42 args := []string{"-ail"}
43 _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, args, notiChan)
46 time.Sleep(time.Millisecond * 10)
49 func TestHandleNoti(t *testing.T) {
50 notiChan := make(chan string, 1)
52 id, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, nil, notiChan)
55 statusNotificationRequest := make(map[string]interface{})
56 statusNotificationRequest[servicemgr.ConstKeyServiceID] = id
57 statusNotificationRequest[servicemgr.ConstKeyStatus] = servicemgr.ConstServiceStatusFinished
59 servicemgr.HandleNoti(statusNotificationRequest)
62 case str := <-notiChan:
64 if strings.Compare(servicemgr.ConstServiceStatusFinished, str) != 0 {
70 func TestSystemtestExecuteRemoteApp(t *testing.T) {
72 router := restapi.NewRouter()
73 server := &http.Server{Addr: fmt.Sprintf(":%d", 56001), Handler: router}
74 go server.ListenAndServe()
75 time.Sleep(time.Duration(1) * time.Second)
78 _, err := servicemgr.ExecuteApp(targetRemoteDeviceAddr, serviceName, nil, nil)
82 time.Sleep(time.Duration(3) * time.Second)
85 if err := server.Shutdown(context.TODO()); err != nil {
89 time.Sleep(time.Millisecond * 10)
92 func TestSystemtestExecuteRemoteAppFailed(t *testing.T) {
94 router := restapi.NewRouter()
95 server := &http.Server{Addr: fmt.Sprintf(":%d", 56001), Handler: router}
96 go server.ListenAndServe()
97 time.Sleep(time.Duration(1) * time.Second)
100 _, err := servicemgr.ExecuteApp(targetRemoteDeviceAddr, "main", nil, nil)
101 time.Sleep(time.Duration(3) * time.Second)
104 if err.Error() != "Failed" {
107 time.Sleep(time.Duration(1) * time.Second)
110 if err := server.Shutdown(context.TODO()); err != nil {
113 time.Sleep(time.Millisecond * 10)