1
1
package messagebirdtest
2
2
3
3
import (
4
+ "bytes"
4
5
"io/ioutil"
5
6
"path/filepath"
6
7
"testing"
7
8
)
8
9
9
10
const testdataDir = "testdata"
10
11
11
- // testdata returns a file's bytes based on the path relative to the testdata
12
+ // Testdata returns a file's bytes based on the path relative to the testdata
12
13
// directory. It fails the test if the testdata file can not be read.
13
- func testdata (t * testing.T , relativePath string ) []byte {
14
+ func Testdata (t * testing.T , relativePath string ) []byte {
14
15
path := filepath .Join (testdataDir , relativePath )
15
16
16
17
b , err := ioutil .ReadFile (path )
@@ -20,3 +21,24 @@ func testdata(t *testing.T, relativePath string) []byte {
20
21
21
22
return b
22
23
}
24
+
25
+ // AssertTestdata gets testdata and asserts it equals actual.
26
+ func AssertTestdata (t * testing.T , relativePath string , actual []byte ) {
27
+ expected := Testdata (t , relativePath )
28
+
29
+ if ! bytes .Equal (expected , actual ) {
30
+ t .Fatalf ("expected %s, got %s" , expected , actual )
31
+ }
32
+ }
33
+
34
+ // AssertEndpointCalled fails the test if the last request was not made to the
35
+ // provided endpoint (e.g. combination of HTTP method and path).
36
+ func AssertEndpointCalled (t * testing.T , method , path string ) {
37
+ if Request .Method != method {
38
+ t .Fatalf ("expected %s, got %s" , method , Request .Method )
39
+ }
40
+
41
+ if escapedPath := Request .URL .EscapedPath (); escapedPath != path {
42
+ t .Fatalf ("expected %s, got %s" , path , escapedPath )
43
+ }
44
+ }
0 commit comments