diff options
| author | Adnan Maolood <[email protected]> | 2021-02-23 17:50:47 -0500 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2021-02-23 17:50:47 -0500 |
| commit | e1c04ee605155b3e7e20630591c4a1936847c13a (patch) | |
| tree | 88c9420949d2e468f5f4ed35004cb66293be1279 /response_test.go | |
| parent | response: Add Close method (diff) | |
| download | go-gemini-e1c04ee605155b3e7e20630591c4a1936847c13a.tar.xz go-gemini-e1c04ee605155b3e7e20630591c4a1936847c13a.zip | |
Make Response an io.ReadCloser
Diffstat (limited to 'response_test.go')
| -rw-r--r-- | response_test.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/response_test.go b/response_test.go index a6226ee..68e0884 100644 --- a/response_test.go +++ b/response_test.go @@ -96,7 +96,7 @@ func TestReadWriteResponse(t *testing.T) { if resp.Meta != test.Meta { t.Errorf("expected meta = %s, got %s", test.Meta, resp.Meta) } - b, _ := io.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.body) body := string(b) if body != test.Body { t.Errorf("expected body = %#v, got %#v", test.Body, body) @@ -107,14 +107,12 @@ func TestReadWriteResponse(t *testing.T) { if test.Err != nil || test.SkipWrite { continue } - resp := &Response{ - Status: test.Status, - Meta: test.Meta, - Body: io.NopCloser(strings.NewReader(test.Body)), - } var b strings.Builder - if err := resp.Write(&b); err != nil { + w := NewResponseWriter(nopCloser{&b}) + w.WriteHeader(test.Status, test.Meta) + io.Copy(w, strings.NewReader(test.Body)) + if err := w.Flush(); err != nil { t.Error(err) continue } @@ -125,3 +123,15 @@ func TestReadWriteResponse(t *testing.T) { } } } + +type nopCloser struct { + io.Writer +} + +func (w nopCloser) Write(b []byte) (int, error) { + return w.Writer.Write(b) +} + +func (nopCloser) Close() error { + return nil +} |