-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport_error_handler_spy_test.go
80 lines (73 loc) · 2.06 KB
/
transport_error_handler_spy_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package sqstransport
import (
"context"
"sync"
)
// Ensure, that TransportErrorHandlerSpy does implement transportErrorHandler.
// If this is not the case, regenerate this file with moq.
var _ transportErrorHandler = &TransportErrorHandlerSpy{}
// TransportErrorHandlerSpy is a mock implementation of transportErrorHandler.
//
// func TestSomethingThatUsestransportErrorHandler(t *testing.T) {
//
// // make and configure a mocked transportErrorHandler
// mockedtransportErrorHandler := &TransportErrorHandlerSpy{
// HandleFunc: func(ctx context.Context, err error) {
// panic("mock out the Handle method")
// },
// }
//
// // use mockedtransportErrorHandler in code that requires transportErrorHandler
// // and then make assertions.
//
// }
type TransportErrorHandlerSpy struct {
// HandleFunc mocks the Handle method.
HandleFunc func(ctx context.Context, err error)
// calls tracks calls to the methods.
calls struct {
// Handle holds details about calls to the Handle method.
Handle []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Err is the err argument value.
Err error
}
}
lockHandle sync.RWMutex
}
// Handle calls HandleFunc.
func (mock *TransportErrorHandlerSpy) Handle(ctx context.Context, err error) {
if mock.HandleFunc == nil {
panic("TransportErrorHandlerSpy.HandleFunc: method is nil but transportErrorHandler.Handle was just called")
}
callInfo := struct {
Ctx context.Context
Err error
}{
Ctx: ctx,
Err: err,
}
mock.lockHandle.Lock()
mock.calls.Handle = append(mock.calls.Handle, callInfo)
mock.lockHandle.Unlock()
mock.HandleFunc(ctx, err)
}
// HandleCalls gets all the calls that were made to Handle.
// Check the length with:
// len(mockedtransportErrorHandler.HandleCalls())
func (mock *TransportErrorHandlerSpy) HandleCalls() []struct {
Ctx context.Context
Err error
} {
var calls []struct {
Ctx context.Context
Err error
}
mock.lockHandle.RLock()
calls = mock.calls.Handle
mock.lockHandle.RUnlock()
return calls
}