aboutsummaryrefslogtreecommitdiff
path: root/server/testdata/type.go
blob: 93041c9a32242f69809a76d85096bce206c55d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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{}")
}