@@ -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\n exit status 2\n " ,
128+ },
111129 }
112130
113131 for _ , test := range tests {
0 commit comments