-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock_test.go
More file actions
39 lines (31 loc) · 739 Bytes
/
Copy pathmock_test.go
File metadata and controls
39 lines (31 loc) · 739 Bytes
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
33
34
35
36
37
38
39
package begger
import (
"fmt"
"net/http"
"time"
"github.com/stretchr/testify/mock"
)
// Implements `http.RoundTripper` interface
type RoundTripperMock struct {
mock.Mock
}
func newRoundTripper() *RoundTripperMock {
return &RoundTripperMock{}
}
func (m *RoundTripperMock) RoundTrip(req *http.Request) (*http.Response, error) {
args := m.Called(req)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*http.Response), args.Error(1)
}
// Implements `Sleeper` interface
type SleeperMock struct {
mock.Mock
}
func NewSleeperMock() *SleeperMock {
return &SleeperMock{}
}
func (s *SleeperMock) Sleep(d time.Duration) {
fmt.Println(fmt.Sprintf("Skip sleeping %+v for faster unit test execution.", d))
}