From: damon92 Date: Thu, 28 Mar 2019 04:27:08 +0000 (+0900) Subject: add discovery test X-Git-Tag: submit/tizen/20190409.085658~15^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d63812ffb5786052dc15d78d8cd17d08edb93ff;p=platform%2Fcore%2Fsystem%2Fedge-orchestration.git add discovery test --- diff --git a/coverage.sh b/coverage.sh index a4bae01..4e6d13a 100755 --- a/coverage.sh +++ b/coverage.sh @@ -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 index 0000000..b999c67 --- /dev/null +++ b/src/discoverymgr/test/device_discovery_test.go @@ -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") + } +} diff --git a/src/restapi/v1/restapi_test.go b/src/restapi/v1/restapi_test.go index cd3b879..595fc25 100644 --- a/src/restapi/v1/restapi_test.go +++ b/src/restapi/v1/restapi_test.go @@ -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) }