test(render): increased unit tests coverage (#3691)
This commit is contained in:
parent
d16fdb15fa
commit
bb2d8cf486
@ -578,3 +578,16 @@ func TestRenderReaderNoContentLength(t *testing.T) {
|
|||||||
assert.Equal(t, headers["Content-Disposition"], w.Header().Get("Content-Disposition"))
|
assert.Equal(t, headers["Content-Disposition"], w.Header().Get("Content-Disposition"))
|
||||||
assert.Equal(t, headers["x-request-id"], w.Header().Get("x-request-id"))
|
assert.Equal(t, headers["x-request-id"], w.Header().Get("x-request-id"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderWriteError(t *testing.T) {
|
||||||
|
data := []interface{}{"value1", "value2"}
|
||||||
|
prefix := "my-prefix:"
|
||||||
|
r := SecureJSON{Data: data, Prefix: prefix}
|
||||||
|
ew := &errorWriter{
|
||||||
|
bufString: prefix,
|
||||||
|
ResponseRecorder: httptest.NewRecorder(),
|
||||||
|
}
|
||||||
|
err := r.Render(ew)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
assert.Equal(t, `write "my-prefix:" error`, err.Error())
|
||||||
|
}
|
||||||
|
@ -156,3 +156,33 @@ func TestResponseWriterStatusCode(t *testing.T) {
|
|||||||
// status must be 200 although we tried to change it
|
// status must be 200 although we tried to change it
|
||||||
assert.Equal(t, http.StatusOK, w.Status())
|
assert.Equal(t, http.StatusOK, w.Status())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mockPusherResponseWriter is an http.ResponseWriter that implements http.Pusher.
|
||||||
|
type mockPusherResponseWriter struct {
|
||||||
|
http.ResponseWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockPusherResponseWriter) Push(target string, opts *http.PushOptions) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// nonPusherResponseWriter is an http.ResponseWriter that does not implement http.Pusher.
|
||||||
|
type nonPusherResponseWriter struct {
|
||||||
|
http.ResponseWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPusherWithPusher(t *testing.T) {
|
||||||
|
rw := &mockPusherResponseWriter{}
|
||||||
|
w := &responseWriter{ResponseWriter: rw}
|
||||||
|
|
||||||
|
pusher := w.Pusher()
|
||||||
|
assert.NotNil(t, pusher, "Expected pusher to be non-nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPusherWithoutPusher(t *testing.T) {
|
||||||
|
rw := &nonPusherResponseWriter{}
|
||||||
|
w := &responseWriter{ResponseWriter: rw}
|
||||||
|
|
||||||
|
pusher := w.Pusher()
|
||||||
|
assert.Nil(t, pusher, "Expected pusher to be nil")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user