-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgroup_test.go
78 lines (65 loc) · 1.47 KB
/
group_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"errors"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/hansmi/paperhooks/pkg/client"
"github.com/hansmi/prometheus-paperless-exporter/internal/testutil"
)
type fakeGroupClient struct {
count int64
err error
}
func (c *fakeGroupClient) ListGroups(ctx context.Context, opts client.ListGroupsOptions) ([]client.Group, *client.Response, error) {
return nil, &client.Response{
ItemCount: c.count,
}, c.err
}
func TestGroup(t *testing.T) {
errTest := errors.New("test error")
for _, tc := range []struct {
name string
cl fakeGroupClient
wantErr error
}{
{
name: "empty",
},
{
name: "listing fails",
cl: fakeGroupClient{
err: errTest,
},
wantErr: errTest,
},
{
name: "groups",
cl: fakeGroupClient{
count: 987,
},
},
} {
t.Run(tc.name, func(t *testing.T) {
c := newGroupCollector(&tc.cl)
err := c.collect(context.Background(), testutil.DiscardMetrics(t))
if diff := cmp.Diff(tc.wantErr, err, cmpopts.EquateErrors()); diff != "" {
t.Errorf("Error diff (-want +got):\n%s", diff)
}
})
}
}
func TestGroupCollect(t *testing.T) {
cl := fakeGroupClient{
count: client.ItemCountUnknown,
}
c := newMultiCollector(newGroupCollector(&cl))
testutil.CollectAndCompare(t, c, ``)
cl.count = 321
testutil.CollectAndCompare(t, c, `
# HELP paperless_groups Number of user groups.
# TYPE paperless_groups gauge
paperless_groups 321
`)
}