blob: 133f8450554b37df1ae758c1616045d4544428f5 [file] [log] [blame]
Jamie Hannafordb2b237f2014-09-15 12:17:47 +02001package testhelper
2
Jamie Hannaford6bcf2582014-09-15 12:52:51 +02003import (
4 "reflect"
5 "testing"
6)
Jamie Hannafordb2b237f2014-09-15 12:17:47 +02007
Jamie Hannaford2964aed2014-09-15 12:20:02 +02008// This function compares two arbitrary values and performs a comparison. If the
9// comparison fails, a fatal error is raised that will fail the test
Jamie Hannaford6bcf2582014-09-15 12:52:51 +020010func Equals(t *testing.T, expected, actual interface{}) {
Jamie Hannafordb2b237f2014-09-15 12:17:47 +020011 if expected != actual {
12 t.Fatalf("Expected [%#v] but got [%#v]", expected, actual)
13 }
14}
15
Jamie Hannaford6bcf2582014-09-15 12:52:51 +020016// This function, like Equals, performs a comparison - but on more complex
17// structures that requires deeper inspection
18func DeepEquals(t *testing.T, actual, expected interface{}) {
19 if !reflect.DeepEqual(actual, expected) {
20 t.Fatalf("Expected %#v but got %#v", expected, actual)
21 }
22}
23
Jamie Hannaford2964aed2014-09-15 12:20:02 +020024// A convenience function for checking whether an error value is an actual error
Jamie Hannafordb2b237f2014-09-15 12:17:47 +020025func CheckErr(t *testing.T, e error) {
26 if e != nil {
27 t.Fatalf("Unexpected error: %#v", e)
28 }
29}