-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Unmarshal API payloads
- Loading branch information
Showing
6 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetAirGradientMeasures(t *testing.T) { | ||
var testCases = []struct { | ||
name string | ||
payloadFile string | ||
err error | ||
}{ | ||
{ | ||
"correct-response", | ||
"testdata/correct_response1.json", | ||
nil, | ||
}, | ||
{ | ||
"correct-response2", | ||
"testdata/correct_response2.json", | ||
nil, | ||
}, | ||
{ | ||
"incorrect-response", | ||
"testdata/incorrect_response1.json", | ||
errors.New("Error unmarshalling JSON"), | ||
}, | ||
} | ||
|
||
for _, tC := range testCases { | ||
t.Run(tC.name, func(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
http.ServeFile(w, r, tC.payloadFile) | ||
})) | ||
defer server.Close() | ||
|
||
_, err := getAirGradientMeasures(server.URL, "SECRET-TOKEN") | ||
assert.Equal(t, tC.err, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"locationId":12345,"locationName":"Test Loc","pm01":null,"pm02":4,"pm10":null,"pm003Count":null,"atmp":24.3,"rhum":52,"rco2":548,"tvoc":93.979355,"wifi":-58,"timestamp":"2023-10-10T03:42:11.000Z","ledMode":"co2","ledCo2Threshold1":1000,"ledCo2Threshold2":2000,"ledCo2ThresholdEnd":4000,"serialno":"aabb12","firmwareVersion":null,"tvocIndex":100,"noxIndex":1}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"locationId":12345,"locationName":"Test Loc","pm01":null,"pm02":4,"pm10":null,"pm003Count":null,"atmp":24.3,"rhum":53.5,"rco2":548,"tvoc":93.979355,"wifi":-58,"timestamp":"2023-10-10T03:42:11.000Z","ledMode":"co2","ledCo2Threshold1":1000,"ledCo2Threshold2":2000,"ledCo2ThresholdEnd":4000,"serialno":"aabb12","firmwareVersion":null,"tvocIndex":100,"noxIndex":1}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Error</title> | ||
</head> | ||
<body> | ||
<pre>Cannot GET /public/api/v1/locations/measures/current1</pre> | ||
</body> | ||
</html> |