add discovery test
authordamon92 <damon92.lee@samsung.com>
Thu, 28 Mar 2019 04:27:08 +0000 (13:27 +0900)
committerdamon92 <damon92.lee@samsung.com>
Thu, 28 Mar 2019 04:27:08 +0000 (13:27 +0900)
coverage.sh
src/discoverymgr/test/device_discovery_test.go [new file with mode: 0644]
src/restapi/v1/restapi_test.go

index a4bae01..4e6d13a 100755 (executable)
@@ -1,8 +1,8 @@
 #! /bin/bash
-
+BASE_DIR=$( cd "$(dirname "$0")" ; pwd )
 export GOPATH=$GOPATH:$BASE_DIR:$BASE_DIR/vendor
-
-go test -v -cover restapi/v1 -coverpkg=servicemgr,devicemgr,restapi -coverprofile cover.out
+ln -sf $BASE_DIR/vendor $BASE_DIR/vendor/src
+go test -v -cover restapi/v1 -coverpkg=servicemgr,devicemgr,restapi,discoverymgr -coverprofile cover.out
 go tool cover -html=cover.out -o cover.html
 
 firefox cover.html
\ No newline at end of file
diff --git a/src/discoverymgr/test/device_discovery_test.go b/src/discoverymgr/test/device_discovery_test.go
new file mode 100644 (file)
index 0000000..b999c67
--- /dev/null
@@ -0,0 +1,55 @@
+package test
+
+import (
+       dm "discoverymgr"
+       "testing"
+)
+
+var data = dm.AppReturnInfo{
+       AppName: "GreetWorldApp",
+       DeviceList: []dm.DeviceReturnInfo{
+               {
+                       DeviceID:   1,
+                       DeviceName: "hello world#1",
+                       Status:     "started",
+                       DeviceIP:   "10.113.175.144",
+               },
+               {
+                       DeviceID:   2,
+                       DeviceName: "hello world#2",
+                       Status:     "progressing",
+                       DeviceIP:   "10.113.175.144",
+               },
+       },
+}
+
+func TestDeviceList(t *testing.T) {
+       registerCh := make(chan error)
+       ServiceNames := []string{"Distributed Web Engine", "Television", "Soundbox"}
+       go RegisterDevice(ServiceNames, registerCh)
+       if err := <-registerCh; err != nil {
+               t.Error("fail")
+       }
+
+       ret, err := dm.DeviceList()
+       if err != nil {
+               t.Error("fail")
+               return
+       }
+       t.Log(ret)
+       if len(ret) != 1 {
+               t.Error("fail")
+       }
+
+       ExitChan <- 1
+
+       ret, err = dm.DeviceList()
+       if err != nil {
+               t.Error("fail")
+               return
+       }
+       t.Log(ret)
+       if len(ret) != 0 {
+               t.Error("fail")
+       }
+}
index cd3b879..595fc25 100644 (file)
@@ -3,6 +3,7 @@ package v1
 import (
        "bytes"
        "devicemgr"
+       "discoverymgr"
        "encoding/json"
        "io/ioutil"
        "log"
@@ -28,6 +29,7 @@ const (
        ConstDeviceResourceUsageNetworkGet = "/api/v1/device/resource/usage/network"
 
        // @TODO discovery mgr URI
+       ConstDiscoverymgrDevices = "/api/v1/discoverymgr/devices"
 
        // Service mgr URI
        ConstServicemgrServices = "/api/v1/servicemgr/services"
@@ -210,6 +212,7 @@ func executeService(t *testing.T, serviceID uint64) {
 func init() {
        devicemgr.InitDeviceMgr()
        servicemgr.InitServiceMap()
+       discoverymgr.InitDiscovery()
 
        router := NewRouter()
        server = httptest.NewServer(router)
@@ -239,6 +242,11 @@ func TestAPIV1DeviceResourceUsageNetworkGet(t *testing.T) {
        testGet(t, targetURI, http.StatusOK)
 }
 
+func TestAPIV1DiscoverymgrDevicesGet(t *testing.T) {
+       targetURI := ConstDiscoverymgrDevices
+       testGet(t, targetURI, http.StatusOK)
+}
+
 func TestAPIV1ServicemgrServicesPost(t *testing.T) {
        registerService(t)
 }