forked from viamrobotics/rdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry_test.go
48 lines (40 loc) · 1.37 KB
/
registry_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package data
import (
"testing"
"go.viam.com/test"
"go.viam.com/rdk/resource"
)
var dummyCollectorConstructor = func(i interface{}, params CollectorParams) (Collector, error) {
return &collector{}, nil
}
func TestRegister(t *testing.T) {
defer func() {
for k := range collectorRegistry {
delete(collectorRegistry, k)
}
}()
md := MethodMetadata{
Subtype: resource.NewDefaultSubtype("type", resource.ResourceTypeComponent),
MethodName: "method",
}
dummyCollectorConstructor = func(i interface{}, params CollectorParams) (Collector, error) {
return &collector{}, nil
}
// Return registered collector if one exists.
RegisterCollector(md, dummyCollectorConstructor)
ret := *CollectorLookup(md)
test.That(t, ret, test.ShouldEqual, dummyCollectorConstructor)
// Return nothing if exact match has not been registered.
wrongType := MethodMetadata{
Subtype: resource.NewDefaultSubtype("wrongType", resource.ResourceTypeComponent),
MethodName: "method",
}
wrongMethod := MethodMetadata{
Subtype: resource.NewDefaultSubtype("type", resource.ResourceTypeComponent),
MethodName: "WrongMethod",
}
test.That(t, CollectorLookup(wrongType), test.ShouldBeNil)
test.That(t, CollectorLookup(wrongMethod), test.ShouldBeNil)
// Panic if try to register same thing twice.
test.That(t, func() { RegisterCollector(md, dummyCollectorConstructor) }, test.ShouldPanic)
}