aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-11 15:57:37 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-11 15:57:37 +0100
commitb0dcf1e78769006ce8154389476d45aa3fb4d654 (patch)
treefc32207461024a5a1cdc83894d784f6fe966a66e
parente7e82cf46149103852da6d5b92eaa11330fe65e4 (diff)
added test that checks for a context deadline
-rw-r--r--handler_test.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/handler_test.go b/handler_test.go
index 2d2a184..6a2e7d8 100644
--- a/handler_test.go
+++ b/handler_test.go
@@ -2,6 +2,7 @@ package stfe
import (
"bytes"
+ "context"
"crypto"
"fmt"
"strings"
@@ -199,7 +200,7 @@ func TestGetSth(t *testing.T) {
}
w := httptest.NewRecorder()
- th.client.EXPECT().GetLatestSignedLogRoot(gomock.Any(), gomock.Any()).Return(table.trsp, table.terr)
+ th.client.EXPECT().GetLatestSignedLogRoot(newDeadlineMatcher(), gomock.Any()).Return(table.trsp, table.terr)
th.getHandler(t, "get-sth").ServeHTTP(w, req)
if w.Code != table.wantCode {
t.Errorf("GET(%s)=%d, want http status code %d", url, w.Code, table.wantCode)
@@ -273,3 +274,27 @@ func mustMarshalRoot(t *testing.T, lr *types.LogRootV1) *trillian.SignedLogRoot
}
return &trillian.SignedLogRoot{LogRoot: rootBytes}
}
+
+// deadlineMatcher implements gomock.Matcher, such that an error is detected if
+// there is no context.Context deadline set
+type deadlineMatcher struct{}
+
+// newDeadlineMatcher returns a new deadlineMatcher
+func newDeadlineMatcher() gomock.Matcher {
+ return &deadlineMatcher{}
+}
+
+// Matches returns true if the passed interface is a context with a deadline
+func (dm *deadlineMatcher) Matches(i interface{}) bool {
+ ctx, ok := i.(context.Context)
+ if !ok {
+ return false
+ }
+ _, ok = ctx.Deadline()
+ return ok
+}
+
+// String is needed to implement gomock.Matcher
+func (dm *deadlineMatcher) String() string {
+ return fmt.Sprintf("deadlineMatcher{}")
+}