MCPcopy Index your code
hub / github.com/netdata/netdata / TestManager_Register

Function TestManager_Register

src/go/plugin/framework/functions/manager_test.go:30–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func TestManager_Register(t *testing.T) {
31 type testInputFn struct {
32 name string
33 invalid bool
34 }
35 tests := map[string]struct {
36 input []testInputFn
37 expected []string
38 }{
39 "valid registration": {
40 input: []testInputFn{
41 {name: "fn1"},
42 {name: "fn2"},
43 },
44 expected: []string{"fn1", "fn2"},
45 },
46 "registration with duplicates": {
47 input: []testInputFn{
48 {name: "fn1"},
49 {name: "fn2"},
50 {name: "fn1"},
51 },
52 expected: []string{"fn1", "fn2"},
53 },
54 "registration with nil functions": {
55 input: []testInputFn{
56 {name: "fn1"},
57 {name: "fn2", invalid: true},
58 },
59 expected: []string{"fn1"},
60 },
61 }
62
63 for name, test := range tests {
64 t.Run(name, func(t *testing.T) {
65 mgr := NewManager()
66
67 for _, v := range test.input {
68 if v.invalid {
69 mgr.Register(v.name, nil)
70 } else {
71 mgr.Register(v.name, func(Function) {})
72 }
73 }
74
75 var got []string
76 for name := range mgr.functionRegistry {
77 got = append(got, name)
78 }
79 sort.Strings(got)
80 sort.Strings(test.expected)
81
82 assert.Equal(t, test.expected, got)
83 })
84 }
85}
86
87func TestManager_RegisterPrefix(t *testing.T) {

Callers

nothing calls this directly

Calls 4

RegisterMethod · 0.95
EqualMethod · 0.80
NewManagerFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…