Skip to content
Myr

test(render): increased unit tests coverage (#3691)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Leonardo de Araujo · committed by GitHub · parent d16fdb1 · Browse files · 2 files+43 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+43 added−0 removed

  • other:+43 added−0 removed

2 files+43 added−0 removed

modified:render/render_test.go+13 added
576 unmodified lines
577 assert.NotContains(t, "Content-Length", w.Header())578 assert.Equal(t, headers["Content-Disposition"], w.Header().Get("Content-Disposition"))579 assert.Equal(t, headers["x-request-id"], w.Header().Get("x-request-id"))580}581582func TestRenderWriteError(t *testing.T) {583 data := []interface{}{"value1", "value2"}584 prefix := "my-prefix:"585 r := SecureJSON{Data: data, Prefix: prefix}586 ew := &errorWriter{587 bufString: prefix,588 ResponseRecorder: httptest.NewRecorder(),589 }590 err := r.Render(ew)591 assert.NotNil(t, err)592 assert.Equal(t, `write "my-prefix:" error`, err.Error())593}
modified:response_writer_test.go+30 added
154 unmodified lines
155156 // status must be 200 although we tried to change it157 assert.Equal(t, http.StatusOK, w.Status())158}159160// mockPusherResponseWriter is an http.ResponseWriter that implements http.Pusher.161type mockPusherResponseWriter struct {162 http.ResponseWriter163}164165func (m *mockPusherResponseWriter) Push(target string, opts *http.PushOptions) error {166 return nil167}168169// nonPusherResponseWriter is an http.ResponseWriter that does not implement http.Pusher.170type nonPusherResponseWriter struct {171 http.ResponseWriter172}173174func TestPusherWithPusher(t *testing.T) {175 rw := &mockPusherResponseWriter{}176 w := &responseWriter{ResponseWriter: rw}177178 pusher := w.Pusher()179 assert.NotNil(t, pusher, "Expected pusher to be non-nil")180}181182func TestPusherWithoutPusher(t *testing.T) {183 rw := &nonPusherResponseWriter{}184 w := &responseWriter{ResponseWriter: rw}185186 pusher := w.Pusher()187 assert.Nil(t, pusher, "Expected pusher to be nil")188}