diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-11 16:48:36 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-11 16:48:36 +0100 |
commit | d8950a4e5c2f46a476483354135c2501e7f9aef5 (patch) | |
tree | 46b05803f8daad3c9fe39acce97060801710a28c /server/testdata/type.go | |
parent | a8c39c65e0494d55e94055867c11e992446a09c8 (diff) |
move test helpers to testdata package
Diffstat (limited to 'server/testdata/type.go')
-rw-r--r-- | server/testdata/type.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/server/testdata/type.go b/server/testdata/type.go new file mode 100644 index 0000000..93041c9 --- /dev/null +++ b/server/testdata/type.go @@ -0,0 +1,32 @@ +package testdata + +import ( + "context" + "fmt" + + "github.com/golang/mock/gomock" +) + +// DeadlineMatcher implements gomock.Matcher, such that an error is raised 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{}") +} |