Skip to content

Commit

Permalink
default response and dial error
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalraja committed Feb 4, 2022
1 parent d3312b6 commit 3e7916e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,20 @@ func checkAlerts(httpFile, statusFile string) error {
Body string
}{Status: 200},
}
uri, err := url.Parse("https://localhost?" + strings.Trim(line[4:], " "))
if err != nil {
log.Println("warn: expects must be url encoded key value (status=200&body=Abc")
continue
}
if status, ok := uri.Query()["status"]; ok {
currentRequest.Expected.Status, _ = strconv.Atoi(status[0])
}
if body, ok := uri.Query()["body"]; ok {
currentRequest.Expected.Body = body[0]
if strings.Trim(line, " ") == "###" {
currentRequest.Expected.Status = 200
} else {
uri, err := url.Parse("https://localhost?" + strings.Trim(line[4:], " "))
if err != nil {
log.Println("warn: expects must be url encoded key value (status=200&body=Abc")
continue
}
if status, ok := uri.Query()["status"]; ok {
currentRequest.Expected.Status, _ = strconv.Atoi(status[0])
}
if body, ok := uri.Query()["body"]; ok {
currentRequest.Expected.Body = body[0]
}
}
startBody = false
} else if strings.Index(line, "#") == 0 {
Expand Down Expand Up @@ -192,7 +196,6 @@ func checkAlerts(httpFile, statusFile string) error {
status, body, err := sendRequest(r)
if err != nil {
log.Println("request failed", r.Method, r.URL)
return
}
matchStatus := r.Expected.Status == 0 || r.Expected.Status == status
matchBody := r.Expected.Body == "" || strings.Contains(body, r.Expected.Body)
Expand Down

0 comments on commit 3e7916e

Please sign in to comment.