forked from adhocteam/script_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_exporter_test.go
More file actions
45 lines (36 loc) · 886 Bytes
/
script_exporter_test.go
File metadata and controls
45 lines (36 loc) · 886 Bytes
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
package main
import (
"testing"
dto "github.com/prometheus/client_model/go"
)
var config = &Config{
Scripts: []*Script{
{"success", "exit 0", 1},
{"failure", "exit 1", 1},
{"timeout", "sleep 5", 1},
},
}
func TestRunScripts(t *testing.T) {
runScripts(config)
results := []struct {
name string
total int
failure int
}{
{"success", 1, 0},
{"failure", 1, 1},
{"timeout", 1, 1},
}
for _, result := range results {
s := &dto.Metric{}
histogram.WithLabelValues(result.name).Write(s)
if samples := int(*s.Histogram.SampleCount); samples != result.total {
t.Errorf("Expecting 1 total sample, received %d", samples)
}
f := &dto.Metric{}
failureHistogram.WithLabelValues(result.name).Write(f)
if samples := int(*f.Histogram.SampleCount); samples != result.failure {
t.Errorf("Expecting 1 failed sample, received %d", samples)
}
}
}