forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.go
56 lines (45 loc) · 1.34 KB
/
users_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
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package metric
import (
"testing"
"github.com/drone/drone/mock"
"github.com/golang/mock/gomock"
"github.com/prometheus/client_golang/prometheus"
)
func TestUserCount(t *testing.T) {
controller := gomock.NewController(t)
// restore the default prometheus registerer
// when the unit test is complete.
snapshot := prometheus.DefaultRegisterer
defer func() {
prometheus.DefaultRegisterer = snapshot
controller.Finish()
}()
// creates a blank registry
registry := prometheus.NewRegistry()
prometheus.DefaultRegisterer = registry
// x2 repository count
count := int64(5)
store := mock.NewMockUserStore(controller)
store.EXPECT().Count(gomock.Any()).Return(count, nil)
UserCount(store)
metrics, err := registry.Gather()
if err != nil {
t.Error(err)
return
}
if want, got := len(metrics), 1; want != got {
t.Errorf("Expect registered metric")
return
}
metric := metrics[0]
if want, got := metric.GetName(), "drone_user_count"; want != got {
t.Errorf("Expect metric name %s, got %s", want, got)
}
if want, got := metric.Metric[0].Gauge.GetValue(), float64(count); want != got {
t.Errorf("Expect metric value %f, got %f", want, got)
}
}