forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_client_mock.go
More file actions
78 lines (71 loc) · 1.79 KB
/
git_client_mock.go
File metadata and controls
78 lines (71 loc) · 1.79 KB
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
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package create
import (
"context"
"sync"
"github.com/cli/cli/v2/git"
)
// gitClientMock is a mock implementation of gitClient.
//
// func TestSomethingThatUsesgitClient(t *testing.T) {
//
// // make and configure a mocked gitClient
// mockedgitClient := &gitClientMock{
// PushFunc: func(ctx context.Context, opts git.PushOptions) error {
// panic("mock out the Push method")
// },
// }
//
// // use mockedgitClient in code that requires gitClient
// // and then make assertions.
//
// }
type gitClientMock struct {
// PushFunc mocks the Push method.
PushFunc func(ctx context.Context, opts git.PushOptions) error
// calls tracks calls to the methods.
calls struct {
// Push holds details about calls to the Push method.
Push []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Opts is the opts argument value.
Opts git.PushOptions
}
}
lockPush sync.RWMutex
}
// Push calls PushFunc.
func (mock *gitClientMock) Push(ctx context.Context, opts git.PushOptions) error {
if mock.PushFunc == nil {
panic("gitClientMock.PushFunc: method is nil but gitClient.Push was just called")
}
callInfo := struct {
Ctx context.Context
Opts git.PushOptions
}{
Ctx: ctx,
Opts: opts,
}
mock.lockPush.Lock()
mock.calls.Push = append(mock.calls.Push, callInfo)
mock.lockPush.Unlock()
return mock.PushFunc(ctx, opts)
}
// PushCalls gets all the calls that were made to Push.
// Check the length with:
// len(mockedgitClient.PushCalls())
func (mock *gitClientMock) PushCalls() []struct {
Ctx context.Context
Opts git.PushOptions
} {
var calls []struct {
Ctx context.Context
Opts git.PushOptions
}
mock.lockPush.RLock()
calls = mock.calls.Push
mock.lockPush.RUnlock()
return calls
}