mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
fix(style): check for json.Unmarshal error returns in tests
Also drop .tests dir, not needed anymore
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user