add endpoint test for alert condition check
* add endpoint test for CheckAlertCondition
* add endpoint test for CheckAlertCondition
verifies CheckAlertCondition handles no-match scenario correctly
* add endpoint test for CheckAlertCondition
verifies CheckAlertCondition handles no-match scenario correctly
* fix build breakage & print error to http response instead of console
@@ -113,14 +113,22 @@ func hello(w http.ResponseWriter, r *http.Request) {
func testCloudSQLConn(w http.ResponseWriter, r *http.Request) {
log.Printf("Serving request: %s", r.URL.Path)
- log.Println("Testing mysql database connection.")
+ fmt.Fprintf(w, "Testing mysql database connection...")
- err := dbConfig.TestConn()
+ db, err := dbConfig.Connect()
if err != nil {
fmt.Fprintf(w, "Failed to ping the database %v", err)
return
}
- fmt.Fprintf(w, "Success\n")
+
+ fmt.Fprintf(w, "testing alert condition check...")
+ s := config.SelectedConfig{}
+ toAlert, err := s.CheckAlertCondition("none", db)
+ if err != nil {
+ fmt.Fprintf(w, "error running alert condition check in no-match senario: %v", err)
+ } else if toAlert {
+ fmt.Fprintf(w, "alert condition check returned false positive in no-match senario: %v", err)
+ }
}
func sendTestEmail(w http.ResponseWriter, r *http.Request) {
