Roll our own method of comparing functions.
Probably unreliable as hell, but seems to work for us.
diff --git a/chain_test.go b/chain_test.go
index e2bf501..f1cf749 100644
--- a/chain_test.go
+++ b/chain_test.go
@@ -4,6 +4,7 @@
import (
"net/http"
"net/http/httptest"
+ "reflect"
"testing"
"github.com/stretchr/testify/assert"
@@ -21,6 +22,14 @@
}
}
+// Not recommended (https://golang.org/pkg/reflect/#Value.Pointer),
+// but the best we can do.
+func funcsEqual(f1, f2 interface{}) bool {
+ val1 := reflect.ValueOf(f1)
+ val2 := reflect.ValueOf(f2)
+ return val1.Pointer() == val2.Pointer()
+}
+
var testApp = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("app\n"))
})
@@ -37,8 +46,8 @@
slice := []Constructor{c1, c2}
chain := New(slice...)
- assert.Equal(t, chain.constructors[0], slice[0])
- assert.Equal(t, chain.constructors[1], slice[1])
+ assert.True(t, funcsEqual(chain.constructors[0], slice[0]))
+ assert.True(t, funcsEqual(chain.constructors[1], slice[1]))
}
func TestThenWorksWithNoMiddleware(t *testing.T) {
@@ -46,7 +55,7 @@
chain := New()
final := chain.Then(testApp)
- assert.Equal(t, final, testApp)
+ assert.True(t, funcsEqual(final, testApp))
})
}