Jamie Hannaford | b2b237f | 2014-09-15 12:17:47 +0200 | [diff] [blame] | 1 | package testhelper |
| 2 | |
Jamie Hannaford | 6bcf258 | 2014-09-15 12:52:51 +0200 | [diff] [blame^] | 3 | import ( |
| 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
Jamie Hannaford | b2b237f | 2014-09-15 12:17:47 +0200 | [diff] [blame] | 7 | |
Jamie Hannaford | 2964aed | 2014-09-15 12:20:02 +0200 | [diff] [blame] | 8 | // 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 Hannaford | 6bcf258 | 2014-09-15 12:52:51 +0200 | [diff] [blame^] | 10 | func Equals(t *testing.T, expected, actual interface{}) { |
Jamie Hannaford | b2b237f | 2014-09-15 12:17:47 +0200 | [diff] [blame] | 11 | if expected != actual { |
| 12 | t.Fatalf("Expected [%#v] but got [%#v]", expected, actual) |
| 13 | } |
| 14 | } |
| 15 | |
Jamie Hannaford | 6bcf258 | 2014-09-15 12:52:51 +0200 | [diff] [blame^] | 16 | // This function, like Equals, performs a comparison - but on more complex |
| 17 | // structures that requires deeper inspection |
| 18 | func 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 Hannaford | 2964aed | 2014-09-15 12:20:02 +0200 | [diff] [blame] | 24 | // A convenience function for checking whether an error value is an actual error |
Jamie Hannaford | b2b237f | 2014-09-15 12:17:47 +0200 | [diff] [blame] | 25 | func CheckErr(t *testing.T, e error) { |
| 26 | if e != nil { |
| 27 | t.Fatalf("Unexpected error: %#v", e) |
| 28 | } |
| 29 | } |