mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
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:
commit
76e6da25fa
@ -47,11 +47,13 @@ func TestRun(t *testing.T) {
|
|||||||
devs := []*pluginapi.Device{
|
devs := []*pluginapi.Device{
|
||||||
{ID: "ADeviceId", Health: pluginapi.Healthy},
|
{ID: "ADeviceId", Health: pluginapi.Healthy},
|
||||||
{ID: "AnotherDeviceId", Health: pluginapi.Healthy},
|
{ID: "AnotherDeviceId", Health: pluginapi.Healthy},
|
||||||
|
{ID: "AThirdDeviceId", Health: pluginapi.Unhealthy},
|
||||||
}
|
}
|
||||||
|
|
||||||
updated := []*pluginapi.Device{
|
updated := []*pluginapi.Device{
|
||||||
{ID: "ADeviceId", Health: pluginapi.Unhealthy},
|
{ID: "ADeviceId", Health: pluginapi.Unhealthy},
|
||||||
{ID: "AThirdDeviceId", Health: pluginapi.Healthy},
|
{ID: "AThirdDeviceId", Health: pluginapi.Healthy},
|
||||||
|
{ID: "AFourthDeviceId", Health: pluginapi.Healthy},
|
||||||
}
|
}
|
||||||
|
|
||||||
callbackCount := 0
|
callbackCount := 0
|
||||||
@ -65,7 +67,7 @@ func TestRun(t *testing.T) {
|
|||||||
|
|
||||||
// Check plugin registration
|
// Check plugin registration
|
||||||
if callbackCount == 0 {
|
if callbackCount == 0 {
|
||||||
require.Len(t, a, 2)
|
require.Len(t, a, 3)
|
||||||
require.Len(t, u, 0)
|
require.Len(t, u, 0)
|
||||||
require.Len(t, r, 0)
|
require.Len(t, r, 0)
|
||||||
}
|
}
|
||||||
@ -73,12 +75,14 @@ func TestRun(t *testing.T) {
|
|||||||
// Check plugin update
|
// Check plugin update
|
||||||
if callbackCount == 1 {
|
if callbackCount == 1 {
|
||||||
require.Len(t, a, 1)
|
require.Len(t, a, 1)
|
||||||
require.Len(t, u, 1)
|
require.Len(t, u, 2)
|
||||||
require.Len(t, r, 1)
|
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].ID, updated[0].ID)
|
||||||
require.Equal(t, u[0].Health, updated[0].Health)
|
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)
|
require.Equal(t, r[0].ID, devs[1].ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +105,7 @@ func TestRun(t *testing.T) {
|
|||||||
e.mutex.Lock()
|
e.mutex.Lock()
|
||||||
defer e.mutex.Unlock()
|
defer e.mutex.Unlock()
|
||||||
|
|
||||||
require.Len(t, e.devices, 2)
|
require.Len(t, e.devices, 3)
|
||||||
for _, dref := range updated {
|
for _, dref := range updated {
|
||||||
d, ok := e.devices[dref.ID]
|
d, ok := e.devices[dref.ID]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user