Skip to content

Commit 0503cfb

Browse files
committed
v1.1.16 added test for HTTPAnswerJSON()
Signed-off-by: miguel <[email protected]>
1 parent 7a381aa commit 0503cfb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

handyhttp_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,23 @@ func TestHTTPJSONToStruct(t *testing.T) {
134134
t.Errorf("Test has failed! %v", err)
135135
}
136136
}
137+
func TestHTTPAnswerJSON(t *testing.T) {
138+
const (
139+
testName = "Forty Two"
140+
testAge = 42
141+
)
142+
143+
httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
144+
var testDummy struct {
145+
Name string `json:"name"`
146+
Age int `json:"age"`
147+
}
148+
149+
testDummy.Name = testName
150+
testDummy.Age = testAge
151+
152+
if err := HTTPAnswerJSON(w, testDummy); err != nil {
153+
t.Error(err)
154+
}
155+
}))
156+
}

0 commit comments

Comments
 (0)