-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
58 lines (46 loc) · 1.29 KB
/
main_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
package main
import (
"os"
"os/exec"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)
// Source https://stackoverflow.com/a/33404435
// Exit with return code 1 if env. var. is not provided
func TestApiTokenCrash(t *testing.T) {
if os.Getenv("BE_CRASHER") == "1" {
main()
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestApiTokenCrash")
cmd.Env = append(os.Environ(), "BE_CRASHER=1")
err := cmd.Run()
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
return
}
t.Fatalf("process ran with err %v, want exit status 1", err)
}
var collector = newSocketCollector()
var ch = make(chan prometheus.Metric)
// Count that the number of metrics is greater than 1
func TestCollectAndCount(t *testing.T) {
maxPackages = 5
metrics, err := fetchMetrics()
if err != nil {
t.Fatalf("Metric collection failed %e", err)
}
exportedMetrics = metrics
number := testutil.CollectAndCount(collector, "socket_score")
if number < 1 {
t.Fatalf("Less than 1 metric was returned. Only %d metrics returned", number)
}
}
// Check linter on metrics
func TestCollectndLint(t *testing.T) {
problem, err := testutil.CollectAndLint(collector, "socket_score")
if err != nil {
t.Errorf("%s", err.Error())
t.Errorf("%s", problem)
}
}