diff --git a/api_test.go b/api_test.go index 2f42c959b..1444e4232 100644 --- a/api_test.go +++ b/api_test.go @@ -844,7 +844,10 @@ func TestVerifyAllGroups(t *testing.T) { } ur := models.AlertsResponse{} - json.Unmarshal(resp.Body.Bytes(), &ur) + err := json.Unmarshal(resp.Body.Bytes(), &ur) + if err != nil { + t.Errorf("Failed to unmarshal response: %s", err) + } if len(ur.AlertGroups) != len(groupTests) { t.Errorf("[%s] Got %d alert(s) in response, expected %d", diff --git a/autocomplete_test.go b/autocomplete_test.go index 8c68ed03c..a11f021c0 100644 --- a/autocomplete_test.go +++ b/autocomplete_test.go @@ -59,7 +59,10 @@ func TestKnownLabelNames(t *testing.T) { } ur := []string{} - json.Unmarshal(resp.Body.Bytes(), &ur) + err := json.Unmarshal(resp.Body.Bytes(), &ur) + if err != nil { + t.Errorf("Failed to unmarshal response: %s", err) + } if len(ur) != len(testCase.Results) { t.Errorf("Invalid number of label names for %s, got %d, expected %d", url, len(ur), len(testCase.Results)) @@ -114,7 +117,10 @@ func TestKnownLabelValues(t *testing.T) { } ur := []string{} - json.Unmarshal(resp.Body.Bytes(), &ur) + err := json.Unmarshal(resp.Body.Bytes(), &ur) + if err != nil { + t.Errorf("Failed to unmarshal response: %s", err) + } if len(ur) != len(testCase.Results) { t.Errorf("Invalid number of label values for %s, got %d, expected %d", url, len(ur), len(testCase.Results)) diff --git a/views_test.go b/views_test.go index f64cb356e..557afcd7c 100644 --- a/views_test.go +++ b/views_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -99,7 +98,10 @@ func TestAlerts(t *testing.T) { } ur := models.AlertsResponse{} - json.Unmarshal(resp.Body.Bytes(), &ur) + err := json.Unmarshal(resp.Body.Bytes(), &ur) + if err != nil { + t.Errorf("Failed to unmarshal response: %s", err) + } if len(ur.Filters) != 3 { t.Errorf("[%s] Got %d filter(s) in response, expected %d", version, len(ur.Filters), 3) } @@ -166,7 +168,10 @@ func TestValidateAllAlerts(t *testing.T) { } ur := models.AlertsResponse{} body := resp.Body.Bytes() - json.Unmarshal(body, &ur) + err := json.Unmarshal(body, &ur) + if err != nil { + t.Errorf("Failed to unmarshal response: %s", err) + } for _, ag := range ur.AlertGroups { for _, a := range ag.Alerts { if !slices.StringInSlice(models.AlertStateList, a.State) { @@ -177,15 +182,6 @@ func TestValidateAllAlerts(t *testing.T) { } } } - // write JSON response to a file, it will be used by (optional) JS tests - // those require actual JSON responses and shouldn't be mocked - if _, err := os.Stat(".tests"); os.IsNotExist(err) { - os.Mkdir(".tests", 0755) - } - err := ioutil.WriteFile(".tests/alerts.json", body, 0644) - if err != nil { - t.Logf("Failed to write .tests/alerts.json: %s", err) - } } } @@ -349,7 +345,10 @@ func TestAutocomplete(t *testing.T) { } ur := []string{} - json.Unmarshal(resp.Body.Bytes(), &ur) + err := json.Unmarshal(resp.Body.Bytes(), &ur) + if err != nil { + t.Errorf("Failed to unmarshal response: %s", err) + } if len(ur) != len(acTest.Results) { t.Errorf("Invalid number of autocomplete hints for %s, got %d, expected %d", url, len(ur), len(acTest.Results))