Skip to content

Commit

Permalink
Add logger to HTTP write error test
Browse files Browse the repository at this point in the history
  • Loading branch information
shabbyrobe committed Jan 18, 2019
1 parent b1770dc commit a58e1f8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions gofakes3_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package gofakes3

import (
"bytes"
"encoding/xml"
"fmt"
"log"
"net/http/httptest"
"testing"
)
Expand All @@ -29,9 +31,13 @@ func TestHttpError(t *testing.T) {
}

func TestHttpErrorWriteFailure(t *testing.T) {
// FIXME: with a pluggable logger, we can intercept the log message to
// verify the write error is handled.
var g GoFakeS3
var buf bytes.Buffer
std := log.New(&buf, "", 0)
logger := StdLog(std)
var g = GoFakeS3{
log: logger,
}

rq := httptest.NewRequest("GET", "/", nil)
rs := httptest.NewRecorder()
g.httpError(&failingResponseWriter{rs}, rq, ErrNoSuchBucket)
Expand All @@ -41,6 +47,9 @@ func TestHttpErrorWriteFailure(t *testing.T) {
if rs.Body.Len() != 0 {
t.Fatal()
}
if buf.String() != "ERR nope\n" {
t.Fatal()
}
}

type failingResponseWriter struct {
Expand Down

0 comments on commit a58e1f8

Please sign in to comment.