executeCommand function add at configuremgr_test.go
[platform/core/system/edge-orchestration.git] / src / configuremgr / configuremgr_test.go
1 package configuremgr_test
2
3 import (
4   "testing"
5   "time"
6   "os/exec"
7   "fmt"
8
9   configuremgr     "configuremgr"
10   mockconfiguremgr "configuremgr/mock"
11 )
12
13
14 func TestBasicMockConfigureMgr(t *testing.T){
15
16   //copy event environment
17   watchDir := "/tmp/foo"
18   src := "./mock/mysum"
19   dst := watchDir
20
21
22   //linking interface
23   //mock function
24
25   //test object
26   configuremgrObj  := configuremgr.Init()
27   configuremgrObj.IDiscoveryMgr.PushConfPath = mockconfiguremgr.PushConfPathDiscoveryDeviceMock
28   configuremgrObj.IScoringMgr.PushLibPath          = mockconfiguremgr.PushLibPathScoringAppMock
29   
30
31   go configuremgrObj.Watch(watchDir)
32
33   //TODO : push /tmp/foo/simple directory using Cmd package
34   time.Sleep(time.Duration(1 * time.Second))
35   
36   
37   //init scenario
38   execCommand("rm -rf /tmp/foo/mysum")
39   time.Sleep(time.Duration(1) * time.Second)
40
41   //user scenario
42   execCommand(fmt.Sprintf("cp -ar %s %s", src, dst))
43   time.Sleep(time.Duration(5) * time.Second)
44
45   configuremgrObj.Done <- true
46 }
47
48
49 func execCommand(command string) {
50   configuremgr.DLog.Println(command)
51   cmd := exec.Command("sh", "-c", command)
52   stdoutStderr, err := cmd.CombinedOutput()
53   configuremgr.DLog.Printf("%s", stdoutStderr)
54   if err != nil {
55     configuremgr.ELog.Fatal(err)
56   }
57 }