Skip to content

Commit

Permalink
Updated discoverymgr mocks and unit test cases for GetDeviceID() meth…
Browse files Browse the repository at this point in the history
…od (#179)

Signed-off-by: ayush.kumar <[email protected]>

- Description: Since getDeviceID() method has been moved to Discovery interface with declaration as GetDeviceID() in #158 , the mocks for discoverymgr along with the test cases are updated accordingly.
  • Loading branch information
ayush-kr authored Nov 18, 2020
1 parent f90495a commit a18e10e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/controller/discoverymgr/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func TestDeviceDetectionRoutine(t *testing.T) {

t.Run("Success", func(t *testing.T) {

discoveryInstance := GetInstance()
//declare mock argument
devicesubchan := make(chan *wrapper.Entity, 20)

Expand Down Expand Up @@ -296,7 +297,7 @@ func TestDeviceDetectionRoutine(t *testing.T) {

presence := false

deviceID, err := getDeviceID()
deviceID, err := discoveryInstance.GetDeviceID()
log.Println(deviceID)
if err != nil {
t.Fatal(err.Error())
Expand Down Expand Up @@ -374,7 +375,7 @@ func TestAddNewServiceName(t *testing.T) {
}
presence := false

deviceID, err := getDeviceID()
deviceID, err := discoveryInstance.GetDeviceID()
if err != nil {
t.Fatal(err.Error())
}
Expand Down Expand Up @@ -420,7 +421,7 @@ func TestRemoveServiceName(t *testing.T) {

isPresence := false

deviceID, err := getDeviceID()
deviceID, err := discoveryInstance.GetDeviceID()
if err != nil {
t.Fatal(err.Error())
}
Expand Down Expand Up @@ -459,7 +460,7 @@ func TestResetServiceName(t *testing.T) {
mockWrapper.EXPECT().SetText(gomock.Any()).Return()
discoveryInstance.ResetServiceName()

deviceID, err := getDeviceID()
deviceID, err := discoveryInstance.GetDeviceID()
if err != nil {
t.Fatal(err.Error())
}
Expand Down Expand Up @@ -554,6 +555,9 @@ func TestDetectNetworkChgRoutine(t *testing.T) {
defer ctrl.Finish()

createMockIns(ctrl)

discoveryInstance := GetInstance()

addDevice(false)

shutdownChan = make(chan struct{})
Expand All @@ -569,7 +573,7 @@ func TestDetectNetworkChgRoutine(t *testing.T) {
ipsub <- []net.IP{net.ParseIP("192.0.2.1")}

time.Sleep(time.Millisecond * time.Duration(10))
deviceID, err := getDeviceID()
deviceID, err := discoveryInstance.GetDeviceID()
if err != nil {
t.Error(err.Error())
}
Expand Down
15 changes: 15 additions & 0 deletions src/controller/discoverymgr/mocks/mocks_discoverymgr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a18e10e

Please sign in to comment.