-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_prometheus_test.go
89 lines (70 loc) · 2.91 KB
/
input_prometheus_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
79
80
81
82
83
84
85
86
87
88
89
package prometheus_test
import (
"testing"
"time"
prometheus "github.com/JorTurFer/xk6-input-prometheus"
"github.com/stretchr/testify/assert"
)
const template string = "2006-01-02T15:04:05Z"
func TestQuery(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "", "")
response, err := client.Query("up")
assert.NoError(t, err)
assert.NotEmpty(t, response.String())
}
func TestQueryWithOperation(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "", "")
response, err := client.Query("sum(alertmanager_notifications_total)")
assert.NoError(t, err)
assert.NotEmpty(t, response.String())
}
func TestQueryWithBasicAuth(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "test", "1234")
response, err := client.Query("sum(alertmanager_notifications_total)")
assert.NoError(t, err)
assert.NotEmpty(t, response.String())
}
func TestQueryWithEmptyResponse(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "", "")
response, err := client.Query("not-existing-metric")
assert.NoError(t, err)
assert.Empty(t, response.String())
}
func TestQueryWithOperationFail(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "", "")
response, err := client.Query("rate(not-existing[5m])")
assert.Error(t, err)
assert.Nil(t, response)
}
func TestQueryRangeWithOperation(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "", "")
start := time.Now().Add(-5 * time.Minute).UTC().Format(template)
end := time.Now().UTC().Format(template)
response, err := client.QueryRange("rate(prometheus_tsdb_head_samples_appended_total[5m])", start, end, "minute")
assert.NoError(t, err)
assert.NotEmpty(t, response.String())
}
func TestQueryRangeWithBasicAuth(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "test", "1234")
start := time.Now().Add(-5 * time.Minute).UTC().Format(template)
end := time.Now().UTC().Format(template)
response, err := client.QueryRange("rate(prometheus_tsdb_head_samples_appended_total[5m])", start, end, "minute")
assert.NoError(t, err)
assert.NotEmpty(t, response.String())
}
func TestQueryRangeWithOperationFail(t *testing.T) {
module := prometheus.Prometheus{}
client := module.NewPrometheusClient("http://demo.robustperception.io:9090", "", "")
start := time.Now().Add(-5 * time.Minute).UTC().Format(template)
end := time.Now().UTC().Format(template)
response, err := client.QueryRange("rate(not-existing[5m])", start, end, "minute")
assert.Error(t, err)
assert.Nil(t, response)
}