Merge pull request #59481 from rojkov/dm-unittests

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

devicemanager: increase code coverege of endpoint's unit test

Particularly cover the code path when an unhealthy device
becomes healthy.
This commit is contained in:
Kubernetes Submit Queue 2018-02-09 10:35:22 -08:00 committed by GitHub
commit 76e6da25fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,11 +47,13 @@ func TestRun(t *testing.T) {
devs := []*pluginapi.Device{
{ID: "ADeviceId", Health: pluginapi.Healthy},
{ID: "AnotherDeviceId", Health: pluginapi.Healthy},
{ID: "AThirdDeviceId", Health: pluginapi.Unhealthy},
}
updated := []*pluginapi.Device{
{ID: "ADeviceId", Health: pluginapi.Unhealthy},
{ID: "AThirdDeviceId", Health: pluginapi.Healthy},
{ID: "AFourthDeviceId", Health: pluginapi.Healthy},
}
callbackCount := 0
@ -65,7 +67,7 @@ func TestRun(t *testing.T) {
// Check plugin registration
if callbackCount == 0 {
require.Len(t, a, 2)
require.Len(t, a, 3)
require.Len(t, u, 0)
require.Len(t, r, 0)
}
@ -73,12 +75,14 @@ func TestRun(t *testing.T) {
// Check plugin update
if callbackCount == 1 {
require.Len(t, a, 1)
require.Len(t, u, 1)
require.Len(t, u, 2)
require.Len(t, r, 1)
require.Equal(t, a[0].ID, updated[1].ID)
require.Equal(t, a[0].ID, updated[2].ID)
require.Equal(t, u[0].ID, updated[0].ID)
require.Equal(t, u[0].Health, updated[0].Health)
require.Equal(t, u[1].ID, updated[1].ID)
require.Equal(t, u[1].Health, updated[1].Health)
require.Equal(t, r[0].ID, devs[1].ID)
}
@ -101,7 +105,7 @@ func TestRun(t *testing.T) {
e.mutex.Lock()
defer e.mutex.Unlock()
require.Len(t, e.devices, 2)
require.Len(t, e.devices, 3)
for _, dref := range updated {
d, ok := e.devices[dref.ID]