Skip to content

Commit

Permalink
Add test for view failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed Mar 7, 2017
1 parent 073803c commit 95111e6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/view/view_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
package view_test

import (
"errors"
"net/http"
"net/http/httptest"
"testing"

"github.com/josephspurrier/gocleanarchitecture/lib/view"
)

type BadResponseWriter struct {
Failed bool
}

func (w *BadResponseWriter) Header() http.Header {
return make(http.Header)
}

func (w *BadResponseWriter) Write(p []byte) (int, error) {
w.Failed = true
return 0, errors.New("Writer failure.")
}

func (w *BadResponseWriter) WriteHeader(i int) {
}

// AssertEqual throws an error if the two values are not equal.
func AssertEqual(t *testing.T, actualValue interface{}, expectedValue interface{}) {
if actualValue != expectedValue {
Expand Down Expand Up @@ -42,4 +59,9 @@ func TestRenderFail(t *testing.T) {
// Fail on template parse error.
v.Render(w, r)
AssertEqual(t, w.Code, http.StatusInternalServerError)

// Fail on file parse error.
br := new(BadResponseWriter)
v.Render(br, r)
AssertEqual(t, br.Failed, true)
}

0 comments on commit 95111e6

Please sign in to comment.