forked from dghubble/gologin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asserts.go
39 lines (34 loc) · 1.06 KB
/
asserts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package testutils provides utilities for writing gologin tests.
package testutils
import (
"io"
"io/ioutil"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
// AssertSuccessNotCalled is a success http.Handler that fails if called.
func AssertSuccessNotCalled(t *testing.T) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) {
assert.Fail(t, "unexpected call to success Handler")
}
return http.HandlerFunc(fn)
}
// AssertFailureNotCalled is a failure http.Handler that fails if called.
func AssertFailureNotCalled(t *testing.T) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) {
assert.Fail(t, "unexpected call to failure Handler")
}
return http.HandlerFunc(fn)
}
// AssertBodyString asserts that a Request Body matches the expected string.
func AssertBodyString(t *testing.T, rc io.ReadCloser, expected string) {
defer rc.Close()
if b, err := ioutil.ReadAll(rc); err == nil {
if string(b) != expected {
t.Errorf("expected %q, got %q", expected, string(b))
}
} else {
t.Errorf("error reading Body")
}
}