package sugarsync import ( "bytes" "io/ioutil" "net/http" "testing" "github.com/stretchr/testify/assert" ) func TestErrorHandler(t *testing.T) { for _, test := range []struct { name string body string code int status string want string }{ { name: "empty", body: "", code: 500, status: "internal error", want: `HTTP error 500 (internal error) returned body: ""`, }, { name: "unknown", body: "

unknown

", code: 500, status: "internal error", want: `HTTP error 500 (internal error) returned body: "

unknown

"`, }, { name: "blank", body: "Nothing here

", code: 500, status: "internal error", want: `HTTP error 500 (internal error) returned body: "Nothing here

"`, }, { name: "real", body: "

an error

\n

Can not move sync folder.

\n

more stuff

", code: 500, status: "internal error", want: `HTTP error 500 (internal error): Can not move sync folder.`, }, } { t.Run(test.name, func(t *testing.T) { resp := http.Response{ Body: ioutil.NopCloser(bytes.NewBufferString(test.body)), StatusCode: test.code, Status: test.status, } got := errorHandler(&resp) assert.Equal(t, test.want, got.Error()) }) } }