github.com/insolar/vanilla@v0.0.0-20201023172447-248fdf805322/cryptkit/digest_signer_mock.go (about) 1 package cryptkit 2 3 // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. 4 5 import ( 6 "sync" 7 mm_atomic "sync/atomic" 8 mm_time "time" 9 10 "github.com/gojuno/minimock/v3" 11 ) 12 13 // DigestSignerMock implements DigestSigner 14 type DigestSignerMock struct { 15 t minimock.Tester 16 17 funcGetSigningMethod func() (s1 SigningMethod) 18 inspectFuncGetSigningMethod func() 19 afterGetSigningMethodCounter uint64 20 beforeGetSigningMethodCounter uint64 21 GetSigningMethodMock mDigestSignerMockGetSigningMethod 22 23 funcSignDigest func(digest Digest) (s1 Signature) 24 inspectFuncSignDigest func(digest Digest) 25 afterSignDigestCounter uint64 26 beforeSignDigestCounter uint64 27 SignDigestMock mDigestSignerMockSignDigest 28 } 29 30 // NewDigestSignerMock returns a mock for DigestSigner 31 func NewDigestSignerMock(t minimock.Tester) *DigestSignerMock { 32 m := &DigestSignerMock{t: t} 33 if controller, ok := t.(minimock.MockController); ok { 34 controller.RegisterMocker(m) 35 } 36 37 m.GetSigningMethodMock = mDigestSignerMockGetSigningMethod{mock: m} 38 39 m.SignDigestMock = mDigestSignerMockSignDigest{mock: m} 40 m.SignDigestMock.callArgs = []*DigestSignerMockSignDigestParams{} 41 42 return m 43 } 44 45 type mDigestSignerMockGetSigningMethod struct { 46 mock *DigestSignerMock 47 defaultExpectation *DigestSignerMockGetSigningMethodExpectation 48 expectations []*DigestSignerMockGetSigningMethodExpectation 49 } 50 51 // DigestSignerMockGetSigningMethodExpectation specifies expectation struct of the DigestSigner.GetSigningMethod 52 type DigestSignerMockGetSigningMethodExpectation struct { 53 mock *DigestSignerMock 54 55 results *DigestSignerMockGetSigningMethodResults 56 Counter uint64 57 } 58 59 // DigestSignerMockGetSigningMethodResults contains results of the DigestSigner.GetSigningMethod 60 type DigestSignerMockGetSigningMethodResults struct { 61 s1 SigningMethod 62 } 63 64 // Expect sets up expected params for DigestSigner.GetSigningMethod 65 func (mmGetSigningMethod *mDigestSignerMockGetSigningMethod) Expect() *mDigestSignerMockGetSigningMethod { 66 if mmGetSigningMethod.mock.funcGetSigningMethod != nil { 67 mmGetSigningMethod.mock.t.Fatalf("DigestSignerMock.GetSigningMethod mock is already set by Set") 68 } 69 70 if mmGetSigningMethod.defaultExpectation == nil { 71 mmGetSigningMethod.defaultExpectation = &DigestSignerMockGetSigningMethodExpectation{} 72 } 73 74 return mmGetSigningMethod 75 } 76 77 // Inspect accepts an inspector function that has same arguments as the DigestSigner.GetSigningMethod 78 func (mmGetSigningMethod *mDigestSignerMockGetSigningMethod) Inspect(f func()) *mDigestSignerMockGetSigningMethod { 79 if mmGetSigningMethod.mock.inspectFuncGetSigningMethod != nil { 80 mmGetSigningMethod.mock.t.Fatalf("Inspect function is already set for DigestSignerMock.GetSigningMethod") 81 } 82 83 mmGetSigningMethod.mock.inspectFuncGetSigningMethod = f 84 85 return mmGetSigningMethod 86 } 87 88 // Return sets up results that will be returned by DigestSigner.GetSigningMethod 89 func (mmGetSigningMethod *mDigestSignerMockGetSigningMethod) Return(s1 SigningMethod) *DigestSignerMock { 90 if mmGetSigningMethod.mock.funcGetSigningMethod != nil { 91 mmGetSigningMethod.mock.t.Fatalf("DigestSignerMock.GetSigningMethod mock is already set by Set") 92 } 93 94 if mmGetSigningMethod.defaultExpectation == nil { 95 mmGetSigningMethod.defaultExpectation = &DigestSignerMockGetSigningMethodExpectation{mock: mmGetSigningMethod.mock} 96 } 97 mmGetSigningMethod.defaultExpectation.results = &DigestSignerMockGetSigningMethodResults{s1} 98 return mmGetSigningMethod.mock 99 } 100 101 //Set uses given function f to mock the DigestSigner.GetSigningMethod method 102 func (mmGetSigningMethod *mDigestSignerMockGetSigningMethod) Set(f func() (s1 SigningMethod)) *DigestSignerMock { 103 if mmGetSigningMethod.defaultExpectation != nil { 104 mmGetSigningMethod.mock.t.Fatalf("Default expectation is already set for the DigestSigner.GetSigningMethod method") 105 } 106 107 if len(mmGetSigningMethod.expectations) > 0 { 108 mmGetSigningMethod.mock.t.Fatalf("Some expectations are already set for the DigestSigner.GetSigningMethod method") 109 } 110 111 mmGetSigningMethod.mock.funcGetSigningMethod = f 112 return mmGetSigningMethod.mock 113 } 114 115 // GetSigningMethod implements DigestSigner 116 func (mmGetSigningMethod *DigestSignerMock) GetSigningMethod() (s1 SigningMethod) { 117 mm_atomic.AddUint64(&mmGetSigningMethod.beforeGetSigningMethodCounter, 1) 118 defer mm_atomic.AddUint64(&mmGetSigningMethod.afterGetSigningMethodCounter, 1) 119 120 if mmGetSigningMethod.inspectFuncGetSigningMethod != nil { 121 mmGetSigningMethod.inspectFuncGetSigningMethod() 122 } 123 124 if mmGetSigningMethod.GetSigningMethodMock.defaultExpectation != nil { 125 mm_atomic.AddUint64(&mmGetSigningMethod.GetSigningMethodMock.defaultExpectation.Counter, 1) 126 127 mm_results := mmGetSigningMethod.GetSigningMethodMock.defaultExpectation.results 128 if mm_results == nil { 129 mmGetSigningMethod.t.Fatal("No results are set for the DigestSignerMock.GetSigningMethod") 130 } 131 return (*mm_results).s1 132 } 133 if mmGetSigningMethod.funcGetSigningMethod != nil { 134 return mmGetSigningMethod.funcGetSigningMethod() 135 } 136 mmGetSigningMethod.t.Fatalf("Unexpected call to DigestSignerMock.GetSigningMethod.") 137 return 138 } 139 140 // GetSigningMethodAfterCounter returns a count of finished DigestSignerMock.GetSigningMethod invocations 141 func (mmGetSigningMethod *DigestSignerMock) GetSigningMethodAfterCounter() uint64 { 142 return mm_atomic.LoadUint64(&mmGetSigningMethod.afterGetSigningMethodCounter) 143 } 144 145 // GetSigningMethodBeforeCounter returns a count of DigestSignerMock.GetSigningMethod invocations 146 func (mmGetSigningMethod *DigestSignerMock) GetSigningMethodBeforeCounter() uint64 { 147 return mm_atomic.LoadUint64(&mmGetSigningMethod.beforeGetSigningMethodCounter) 148 } 149 150 // MinimockGetSigningMethodDone returns true if the count of the GetSigningMethod invocations corresponds 151 // the number of defined expectations 152 func (m *DigestSignerMock) MinimockGetSigningMethodDone() bool { 153 for _, e := range m.GetSigningMethodMock.expectations { 154 if mm_atomic.LoadUint64(&e.Counter) < 1 { 155 return false 156 } 157 } 158 159 // if default expectation was set then invocations count should be greater than zero 160 if m.GetSigningMethodMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetSigningMethodCounter) < 1 { 161 return false 162 } 163 // if func was set then invocations count should be greater than zero 164 if m.funcGetSigningMethod != nil && mm_atomic.LoadUint64(&m.afterGetSigningMethodCounter) < 1 { 165 return false 166 } 167 return true 168 } 169 170 // MinimockGetSigningMethodInspect logs each unmet expectation 171 func (m *DigestSignerMock) MinimockGetSigningMethodInspect() { 172 for _, e := range m.GetSigningMethodMock.expectations { 173 if mm_atomic.LoadUint64(&e.Counter) < 1 { 174 m.t.Error("Expected call to DigestSignerMock.GetSigningMethod") 175 } 176 } 177 178 // if default expectation was set then invocations count should be greater than zero 179 if m.GetSigningMethodMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetSigningMethodCounter) < 1 { 180 m.t.Error("Expected call to DigestSignerMock.GetSigningMethod") 181 } 182 // if func was set then invocations count should be greater than zero 183 if m.funcGetSigningMethod != nil && mm_atomic.LoadUint64(&m.afterGetSigningMethodCounter) < 1 { 184 m.t.Error("Expected call to DigestSignerMock.GetSigningMethod") 185 } 186 } 187 188 type mDigestSignerMockSignDigest struct { 189 mock *DigestSignerMock 190 defaultExpectation *DigestSignerMockSignDigestExpectation 191 expectations []*DigestSignerMockSignDigestExpectation 192 193 callArgs []*DigestSignerMockSignDigestParams 194 mutex sync.RWMutex 195 } 196 197 // DigestSignerMockSignDigestExpectation specifies expectation struct of the DigestSigner.SignDigest 198 type DigestSignerMockSignDigestExpectation struct { 199 mock *DigestSignerMock 200 params *DigestSignerMockSignDigestParams 201 results *DigestSignerMockSignDigestResults 202 Counter uint64 203 } 204 205 // DigestSignerMockSignDigestParams contains parameters of the DigestSigner.SignDigest 206 type DigestSignerMockSignDigestParams struct { 207 digest Digest 208 } 209 210 // DigestSignerMockSignDigestResults contains results of the DigestSigner.SignDigest 211 type DigestSignerMockSignDigestResults struct { 212 s1 Signature 213 } 214 215 // Expect sets up expected params for DigestSigner.SignDigest 216 func (mmSignDigest *mDigestSignerMockSignDigest) Expect(digest Digest) *mDigestSignerMockSignDigest { 217 if mmSignDigest.mock.funcSignDigest != nil { 218 mmSignDigest.mock.t.Fatalf("DigestSignerMock.SignDigest mock is already set by Set") 219 } 220 221 if mmSignDigest.defaultExpectation == nil { 222 mmSignDigest.defaultExpectation = &DigestSignerMockSignDigestExpectation{} 223 } 224 225 mmSignDigest.defaultExpectation.params = &DigestSignerMockSignDigestParams{digest} 226 for _, e := range mmSignDigest.expectations { 227 if minimock.Equal(e.params, mmSignDigest.defaultExpectation.params) { 228 mmSignDigest.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmSignDigest.defaultExpectation.params) 229 } 230 } 231 232 return mmSignDigest 233 } 234 235 // Inspect accepts an inspector function that has same arguments as the DigestSigner.SignDigest 236 func (mmSignDigest *mDigestSignerMockSignDigest) Inspect(f func(digest Digest)) *mDigestSignerMockSignDigest { 237 if mmSignDigest.mock.inspectFuncSignDigest != nil { 238 mmSignDigest.mock.t.Fatalf("Inspect function is already set for DigestSignerMock.SignDigest") 239 } 240 241 mmSignDigest.mock.inspectFuncSignDigest = f 242 243 return mmSignDigest 244 } 245 246 // Return sets up results that will be returned by DigestSigner.SignDigest 247 func (mmSignDigest *mDigestSignerMockSignDigest) Return(s1 Signature) *DigestSignerMock { 248 if mmSignDigest.mock.funcSignDigest != nil { 249 mmSignDigest.mock.t.Fatalf("DigestSignerMock.SignDigest mock is already set by Set") 250 } 251 252 if mmSignDigest.defaultExpectation == nil { 253 mmSignDigest.defaultExpectation = &DigestSignerMockSignDigestExpectation{mock: mmSignDigest.mock} 254 } 255 mmSignDigest.defaultExpectation.results = &DigestSignerMockSignDigestResults{s1} 256 return mmSignDigest.mock 257 } 258 259 //Set uses given function f to mock the DigestSigner.SignDigest method 260 func (mmSignDigest *mDigestSignerMockSignDigest) Set(f func(digest Digest) (s1 Signature)) *DigestSignerMock { 261 if mmSignDigest.defaultExpectation != nil { 262 mmSignDigest.mock.t.Fatalf("Default expectation is already set for the DigestSigner.SignDigest method") 263 } 264 265 if len(mmSignDigest.expectations) > 0 { 266 mmSignDigest.mock.t.Fatalf("Some expectations are already set for the DigestSigner.SignDigest method") 267 } 268 269 mmSignDigest.mock.funcSignDigest = f 270 return mmSignDigest.mock 271 } 272 273 // When sets expectation for the DigestSigner.SignDigest which will trigger the result defined by the following 274 // Then helper 275 func (mmSignDigest *mDigestSignerMockSignDigest) When(digest Digest) *DigestSignerMockSignDigestExpectation { 276 if mmSignDigest.mock.funcSignDigest != nil { 277 mmSignDigest.mock.t.Fatalf("DigestSignerMock.SignDigest mock is already set by Set") 278 } 279 280 expectation := &DigestSignerMockSignDigestExpectation{ 281 mock: mmSignDigest.mock, 282 params: &DigestSignerMockSignDigestParams{digest}, 283 } 284 mmSignDigest.expectations = append(mmSignDigest.expectations, expectation) 285 return expectation 286 } 287 288 // Then sets up DigestSigner.SignDigest return parameters for the expectation previously defined by the When method 289 func (e *DigestSignerMockSignDigestExpectation) Then(s1 Signature) *DigestSignerMock { 290 e.results = &DigestSignerMockSignDigestResults{s1} 291 return e.mock 292 } 293 294 // SignDigest implements DigestSigner 295 func (mmSignDigest *DigestSignerMock) SignDigest(digest Digest) (s1 Signature) { 296 mm_atomic.AddUint64(&mmSignDigest.beforeSignDigestCounter, 1) 297 defer mm_atomic.AddUint64(&mmSignDigest.afterSignDigestCounter, 1) 298 299 if mmSignDigest.inspectFuncSignDigest != nil { 300 mmSignDigest.inspectFuncSignDigest(digest) 301 } 302 303 mm_params := &DigestSignerMockSignDigestParams{digest} 304 305 // Record call args 306 mmSignDigest.SignDigestMock.mutex.Lock() 307 mmSignDigest.SignDigestMock.callArgs = append(mmSignDigest.SignDigestMock.callArgs, mm_params) 308 mmSignDigest.SignDigestMock.mutex.Unlock() 309 310 for _, e := range mmSignDigest.SignDigestMock.expectations { 311 if minimock.Equal(e.params, mm_params) { 312 mm_atomic.AddUint64(&e.Counter, 1) 313 return e.results.s1 314 } 315 } 316 317 if mmSignDigest.SignDigestMock.defaultExpectation != nil { 318 mm_atomic.AddUint64(&mmSignDigest.SignDigestMock.defaultExpectation.Counter, 1) 319 mm_want := mmSignDigest.SignDigestMock.defaultExpectation.params 320 mm_got := DigestSignerMockSignDigestParams{digest} 321 if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { 322 mmSignDigest.t.Errorf("DigestSignerMock.SignDigest got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) 323 } 324 325 mm_results := mmSignDigest.SignDigestMock.defaultExpectation.results 326 if mm_results == nil { 327 mmSignDigest.t.Fatal("No results are set for the DigestSignerMock.SignDigest") 328 } 329 return (*mm_results).s1 330 } 331 if mmSignDigest.funcSignDigest != nil { 332 return mmSignDigest.funcSignDigest(digest) 333 } 334 mmSignDigest.t.Fatalf("Unexpected call to DigestSignerMock.SignDigest. %v", digest) 335 return 336 } 337 338 // SignDigestAfterCounter returns a count of finished DigestSignerMock.SignDigest invocations 339 func (mmSignDigest *DigestSignerMock) SignDigestAfterCounter() uint64 { 340 return mm_atomic.LoadUint64(&mmSignDigest.afterSignDigestCounter) 341 } 342 343 // SignDigestBeforeCounter returns a count of DigestSignerMock.SignDigest invocations 344 func (mmSignDigest *DigestSignerMock) SignDigestBeforeCounter() uint64 { 345 return mm_atomic.LoadUint64(&mmSignDigest.beforeSignDigestCounter) 346 } 347 348 // Calls returns a list of arguments used in each call to DigestSignerMock.SignDigest. 349 // The list is in the same order as the calls were made (i.e. recent calls have a higher index) 350 func (mmSignDigest *mDigestSignerMockSignDigest) Calls() []*DigestSignerMockSignDigestParams { 351 mmSignDigest.mutex.RLock() 352 353 argCopy := make([]*DigestSignerMockSignDigestParams, len(mmSignDigest.callArgs)) 354 copy(argCopy, mmSignDigest.callArgs) 355 356 mmSignDigest.mutex.RUnlock() 357 358 return argCopy 359 } 360 361 // MinimockSignDigestDone returns true if the count of the SignDigest invocations corresponds 362 // the number of defined expectations 363 func (m *DigestSignerMock) MinimockSignDigestDone() bool { 364 for _, e := range m.SignDigestMock.expectations { 365 if mm_atomic.LoadUint64(&e.Counter) < 1 { 366 return false 367 } 368 } 369 370 // if default expectation was set then invocations count should be greater than zero 371 if m.SignDigestMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSignDigestCounter) < 1 { 372 return false 373 } 374 // if func was set then invocations count should be greater than zero 375 if m.funcSignDigest != nil && mm_atomic.LoadUint64(&m.afterSignDigestCounter) < 1 { 376 return false 377 } 378 return true 379 } 380 381 // MinimockSignDigestInspect logs each unmet expectation 382 func (m *DigestSignerMock) MinimockSignDigestInspect() { 383 for _, e := range m.SignDigestMock.expectations { 384 if mm_atomic.LoadUint64(&e.Counter) < 1 { 385 m.t.Errorf("Expected call to DigestSignerMock.SignDigest with params: %#v", *e.params) 386 } 387 } 388 389 // if default expectation was set then invocations count should be greater than zero 390 if m.SignDigestMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSignDigestCounter) < 1 { 391 if m.SignDigestMock.defaultExpectation.params == nil { 392 m.t.Error("Expected call to DigestSignerMock.SignDigest") 393 } else { 394 m.t.Errorf("Expected call to DigestSignerMock.SignDigest with params: %#v", *m.SignDigestMock.defaultExpectation.params) 395 } 396 } 397 // if func was set then invocations count should be greater than zero 398 if m.funcSignDigest != nil && mm_atomic.LoadUint64(&m.afterSignDigestCounter) < 1 { 399 m.t.Error("Expected call to DigestSignerMock.SignDigest") 400 } 401 } 402 403 // MinimockFinish checks that all mocked methods have been called the expected number of times 404 func (m *DigestSignerMock) MinimockFinish() { 405 if !m.minimockDone() { 406 m.MinimockGetSigningMethodInspect() 407 408 m.MinimockSignDigestInspect() 409 m.t.FailNow() 410 } 411 } 412 413 // MinimockWait waits for all mocked methods to be called the expected number of times 414 func (m *DigestSignerMock) MinimockWait(timeout mm_time.Duration) { 415 timeoutCh := mm_time.After(timeout) 416 for { 417 if m.minimockDone() { 418 return 419 } 420 select { 421 case <-timeoutCh: 422 m.MinimockFinish() 423 return 424 case <-mm_time.After(10 * mm_time.Millisecond): 425 } 426 } 427 } 428 429 func (m *DigestSignerMock) minimockDone() bool { 430 done := true 431 return done && 432 m.MinimockGetSigningMethodDone() && 433 m.MinimockSignDigestDone() 434 }