spec_mock.go 4.49 KB
Newer Older
songlinfeng's avatar
songlinfeng committed
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq

package oci

import (
	"github.com/opencontainers/runtime-spec/specs-go"
	"sync"
)

// Ensure, that SpecMock does implement Spec.
// If this is not the case, regenerate this file with moq.
var _ Spec = &SpecMock{}

// SpecMock is a mock implementation of Spec.
//
//	func TestSomethingThatUsesSpec(t *testing.T) {
//
//		// make and configure a mocked Spec
//		mockedSpec := &SpecMock{
//			FlushFunc: func() error {
//				panic("mock out the Flush method")
//			},
//			LoadFunc: func() (*specs.Spec, error) {
//				panic("mock out the Load method")
//			},
//			LookupEnvFunc: func(s string) (string, bool) {
//				panic("mock out the LookupEnv method")
//			},
//			ModifyFunc: func(specModifier SpecModifier) error {
//				panic("mock out the Modify method")
//			},
//		}
//
//		// use mockedSpec in code that requires Spec
//		// and then make assertions.
//
//	}
type SpecMock struct {
	// FlushFunc mocks the Flush method.
	FlushFunc func() error

	// LoadFunc mocks the Load method.
	LoadFunc func() (*specs.Spec, error)

	// LookupEnvFunc mocks the LookupEnv method.
	LookupEnvFunc func(s string) (string, bool)

	// ModifyFunc mocks the Modify method.
	ModifyFunc func(specModifier SpecModifier) error

	// calls tracks calls to the methods.
	calls struct {
		// Flush holds details about calls to the Flush method.
		Flush []struct {
		}
		// Load holds details about calls to the Load method.
		Load []struct {
		}
		// LookupEnv holds details about calls to the LookupEnv method.
		LookupEnv []struct {
			// S is the s argument value.
			S string
		}
		// Modify holds details about calls to the Modify method.
		Modify []struct {
			// SpecModifier is the specModifier argument value.
			SpecModifier SpecModifier
		}
	}
	lockFlush     sync.RWMutex
	lockLoad      sync.RWMutex
	lockLookupEnv sync.RWMutex
	lockModify    sync.RWMutex
}

// Flush calls FlushFunc.
func (mock *SpecMock) Flush() error {
	callInfo := struct {
	}{}
	mock.lockFlush.Lock()
	mock.calls.Flush = append(mock.calls.Flush, callInfo)
	mock.lockFlush.Unlock()
	if mock.FlushFunc == nil {
		var (
			errOut error
		)
		return errOut
	}
	return mock.FlushFunc()
}

// FlushCalls gets all the calls that were made to Flush.
// Check the length with:
//
//	len(mockedSpec.FlushCalls())
func (mock *SpecMock) FlushCalls() []struct {
} {
	var calls []struct {
	}
	mock.lockFlush.RLock()
	calls = mock.calls.Flush
	mock.lockFlush.RUnlock()
	return calls
}

// Load calls LoadFunc.
func (mock *SpecMock) Load() (*specs.Spec, error) {
	callInfo := struct {
	}{}
	mock.lockLoad.Lock()
	mock.calls.Load = append(mock.calls.Load, callInfo)
	mock.lockLoad.Unlock()
	if mock.LoadFunc == nil {
		var (
			specOut *specs.Spec
			errOut  error
		)
		return specOut, errOut
	}
	return mock.LoadFunc()
}

// LoadCalls gets all the calls that were made to Load.
// Check the length with:
//
//	len(mockedSpec.LoadCalls())
func (mock *SpecMock) LoadCalls() []struct {
} {
	var calls []struct {
	}
	mock.lockLoad.RLock()
	calls = mock.calls.Load
	mock.lockLoad.RUnlock()
	return calls
}

// LookupEnv calls LookupEnvFunc.
func (mock *SpecMock) LookupEnv(s string) (string, bool) {
	callInfo := struct {
		S string
	}{
		S: s,
	}
	mock.lockLookupEnv.Lock()
	mock.calls.LookupEnv = append(mock.calls.LookupEnv, callInfo)
	mock.lockLookupEnv.Unlock()
	if mock.LookupEnvFunc == nil {
		var (
			sOut string
			bOut bool
		)
		return sOut, bOut
	}
	return mock.LookupEnvFunc(s)
}

// LookupEnvCalls gets all the calls that were made to LookupEnv.
// Check the length with:
//
//	len(mockedSpec.LookupEnvCalls())
func (mock *SpecMock) LookupEnvCalls() []struct {
	S string
} {
	var calls []struct {
		S string
	}
	mock.lockLookupEnv.RLock()
	calls = mock.calls.LookupEnv
	mock.lockLookupEnv.RUnlock()
	return calls
}

// Modify calls ModifyFunc.
func (mock *SpecMock) Modify(specModifier SpecModifier) error {
	callInfo := struct {
		SpecModifier SpecModifier
	}{
		SpecModifier: specModifier,
	}
	mock.lockModify.Lock()
	mock.calls.Modify = append(mock.calls.Modify, callInfo)
	mock.lockModify.Unlock()
	if mock.ModifyFunc == nil {
		var (
			errOut error
		)
		return errOut
	}
	return mock.ModifyFunc(specModifier)
}

// ModifyCalls gets all the calls that were made to Modify.
// Check the length with:
//
//	len(mockedSpec.ModifyCalls())
func (mock *SpecMock) ModifyCalls() []struct {
	SpecModifier SpecModifier
} {
	var calls []struct {
		SpecModifier SpecModifier
	}
	mock.lockModify.RLock()
	calls = mock.calls.Modify
	mock.lockModify.RUnlock()
	return calls
}