...
1
16
17 package metrics
18
19 import (
20 "fmt"
21 "testing"
22
23 "k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache"
24 )
25
26 func TestMetricCollection(t *testing.T) {
27 dsw := cache.NewDesiredStateOfWorld()
28 asw := cache.NewActualStateOfWorld()
29 fakePlugin := cache.PluginInfo{
30 SocketPath: fmt.Sprintf("fake/path/plugin.sock"),
31 }
32
33 err := dsw.AddOrUpdatePlugin(fakePlugin.SocketPath)
34 if err != nil {
35 t.Fatalf("AddOrUpdatePlugin failed. Expected: <no error> Actual: <%v>", err)
36 }
37
38
39 err = asw.AddPlugin(fakePlugin)
40 if err != nil {
41 t.Fatalf("AddOrUpdatePlugin failed. Expected: <no error> Actual: <%v>", err)
42 }
43
44 metricCollector := &totalPluginsCollector{asw: asw, dsw: dsw}
45
46
47 count := metricCollector.getPluginCount()
48 if len(count) != 2 {
49 t.Errorf("getPluginCount failed. Expected <2> states, got <%d>", len(count))
50 }
51
52 dswCount, ok := count["desired_state_of_world"]
53 if !ok {
54 t.Errorf("getPluginCount failed. Expected <desired_state_of_world>, got nothing")
55 }
56
57 fakePluginCount := dswCount["fake/path/plugin.sock"]
58 if fakePluginCount != 1 {
59 t.Errorf("getPluginCount failed. Expected <1> fake/path/plugin.sock in DesiredStateOfWorld, got <%d>",
60 fakePluginCount)
61 }
62
63 aswCount, ok := count["actual_state_of_world"]
64 if !ok {
65 t.Errorf("getPluginCount failed. Expected <actual_state_of_world>, got nothing")
66 }
67
68 fakePluginCount = aswCount["fake/path/plugin.sock"]
69 if fakePluginCount != 1 {
70 t.Errorf("getPluginCount failed. Expected <1> fake/path/plugin.sock in ActualStateOfWorld, got <%d>",
71 fakePluginCount)
72 }
73 }
74
View as plain text