Factor out error type checks

This commit is contained in:
Bryan Boreham committed 2014-10-22 18:24:02 +01:00
1 parent 0a5990bd6e
commit 94a812d98f
3 files changed
+20 -15

No files matched your search

+15
View File
@@ -1,6 +1,7 @@
package weavedns
import (
"reflect"
"testing"
)
@@ -15,3 +16,17 @@ func assertStatus(t *testing.T, got int, wanted int, desc string) {
t.Fatalf("Expected %s %d but got %d", desc, wanted, got)
}
}
func assertErrorInterface(t *testing.T, got interface{}, wanted interface{}, desc string) {
got_t, wanted_t := reflect.TypeOf(got), reflect.TypeOf(wanted).Elem()
if !got_t.Implements(wanted_t) {
t.Fatalf("Expected %s but got %s (%s)", wanted_t.String(), got_t.String(), desc)
}
}
func assertErrorType(t *testing.T, got interface{}, wanted interface{}, desc string) {
got_t, wanted_t := reflect.TypeOf(got), reflect.TypeOf(wanted).Elem()
if got_t != wanted_t {
t.Fatalf("Expected %s but got %s (%s)", wanted_t.String(), got_t.String(), desc)
}
}