(t *testing.T)
| 28 | } |
| 29 | |
| 30 | func 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 | |
| 87 | func TestManager_RegisterPrefix(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…