Skip to content

Commit 251be8a

Browse files
committed
Extend Tests
1 parent 17412e1 commit 251be8a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cmd/query_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ func TestQueryCmd(t *testing.T) {
108108
args: []string{"run", "../main.go", "query", "--query", "up{job=\"prometheus\"}"},
109109
expected: "[OK] - 1 Metrics OK | up_instance_localhost_job_prometheus=1;10;20\n",
110110
},
111+
{
112+
name: "query-threshold-ok",
113+
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
114+
w.WriteHeader(http.StatusOK)
115+
w.Write([]byte(`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","instance":"localhost","job":"prometheus"},"value":[1668782473.835,"100"]}]}}`))
116+
})),
117+
args: []string{"run", "../main.go", "query", "--query", "up{job=\"prometheus\"}", "-w", "0:", "-c", "0:"},
118+
expected: "[OK] - 1 Metrics OK | up_instance_localhost_job_prometheus=100\n",
119+
},
120+
{
121+
name: "query-threshold-critical",
122+
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
123+
w.WriteHeader(http.StatusOK)
124+
w.Write([]byte(`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","instance":"localhost","job":"prometheus"},"value":[1668782473.835,"-100"]}]}}`))
125+
})),
126+
args: []string{"run", "../main.go", "query", "--query", "up{job=\"prometheus\"}", "-w", "0:", "-c", "0:"},
127+
expected: "[CRITICAL] - 1 Metrics: 1 Critical - 0 Warning - 0 Ok\n \\_[CRITICAL] up{instance=\"localhost\", job=\"prometheus\"} - value: -100\n | up_instance_localhost_job_prometheus=-100\nexit status 2\n",
128+
},
111129
}
112130

113131
for _, test := range tests {

0 commit comments

Comments
 (0)