github.com/braveheart12/just@v0.8.7/testutils/cryptography_service_mock.go (about) 1 package testutils 2 3 /* 4 DO NOT EDIT! 5 This code was generated automatically using github.com/gojuno/minimock v1.9 6 The original interface "CryptographyService" can be found in github.com/insolar/insolar/core 7 */ 8 import ( 9 crypto "crypto" 10 "sync/atomic" 11 "time" 12 13 "github.com/gojuno/minimock" 14 core "github.com/insolar/insolar/core" 15 16 testify_assert "github.com/stretchr/testify/assert" 17 ) 18 19 //CryptographyServiceMock implements github.com/insolar/insolar/core.CryptographyService 20 type CryptographyServiceMock struct { 21 t minimock.Tester 22 23 GetPublicKeyFunc func() (r crypto.PublicKey, r1 error) 24 GetPublicKeyCounter uint64 25 GetPublicKeyPreCounter uint64 26 GetPublicKeyMock mCryptographyServiceMockGetPublicKey 27 28 SignFunc func(p []byte) (r *core.Signature, r1 error) 29 SignCounter uint64 30 SignPreCounter uint64 31 SignMock mCryptographyServiceMockSign 32 33 VerifyFunc func(p crypto.PublicKey, p1 core.Signature, p2 []byte) (r bool) 34 VerifyCounter uint64 35 VerifyPreCounter uint64 36 VerifyMock mCryptographyServiceMockVerify 37 } 38 39 //NewCryptographyServiceMock returns a mock for github.com/insolar/insolar/core.CryptographyService 40 func NewCryptographyServiceMock(t minimock.Tester) *CryptographyServiceMock { 41 m := &CryptographyServiceMock{t: t} 42 43 if controller, ok := t.(minimock.MockController); ok { 44 controller.RegisterMocker(m) 45 } 46 47 m.GetPublicKeyMock = mCryptographyServiceMockGetPublicKey{mock: m} 48 m.SignMock = mCryptographyServiceMockSign{mock: m} 49 m.VerifyMock = mCryptographyServiceMockVerify{mock: m} 50 51 return m 52 } 53 54 type mCryptographyServiceMockGetPublicKey struct { 55 mock *CryptographyServiceMock 56 mainExpectation *CryptographyServiceMockGetPublicKeyExpectation 57 expectationSeries []*CryptographyServiceMockGetPublicKeyExpectation 58 } 59 60 type CryptographyServiceMockGetPublicKeyExpectation struct { 61 result *CryptographyServiceMockGetPublicKeyResult 62 } 63 64 type CryptographyServiceMockGetPublicKeyResult struct { 65 r crypto.PublicKey 66 r1 error 67 } 68 69 //Expect specifies that invocation of CryptographyService.GetPublicKey is expected from 1 to Infinity times 70 func (m *mCryptographyServiceMockGetPublicKey) Expect() *mCryptographyServiceMockGetPublicKey { 71 m.mock.GetPublicKeyFunc = nil 72 m.expectationSeries = nil 73 74 if m.mainExpectation == nil { 75 m.mainExpectation = &CryptographyServiceMockGetPublicKeyExpectation{} 76 } 77 78 return m 79 } 80 81 //Return specifies results of invocation of CryptographyService.GetPublicKey 82 func (m *mCryptographyServiceMockGetPublicKey) Return(r crypto.PublicKey, r1 error) *CryptographyServiceMock { 83 m.mock.GetPublicKeyFunc = nil 84 m.expectationSeries = nil 85 86 if m.mainExpectation == nil { 87 m.mainExpectation = &CryptographyServiceMockGetPublicKeyExpectation{} 88 } 89 m.mainExpectation.result = &CryptographyServiceMockGetPublicKeyResult{r, r1} 90 return m.mock 91 } 92 93 //ExpectOnce specifies that invocation of CryptographyService.GetPublicKey is expected once 94 func (m *mCryptographyServiceMockGetPublicKey) ExpectOnce() *CryptographyServiceMockGetPublicKeyExpectation { 95 m.mock.GetPublicKeyFunc = nil 96 m.mainExpectation = nil 97 98 expectation := &CryptographyServiceMockGetPublicKeyExpectation{} 99 100 m.expectationSeries = append(m.expectationSeries, expectation) 101 return expectation 102 } 103 104 func (e *CryptographyServiceMockGetPublicKeyExpectation) Return(r crypto.PublicKey, r1 error) { 105 e.result = &CryptographyServiceMockGetPublicKeyResult{r, r1} 106 } 107 108 //Set uses given function f as a mock of CryptographyService.GetPublicKey method 109 func (m *mCryptographyServiceMockGetPublicKey) Set(f func() (r crypto.PublicKey, r1 error)) *CryptographyServiceMock { 110 m.mainExpectation = nil 111 m.expectationSeries = nil 112 113 m.mock.GetPublicKeyFunc = f 114 return m.mock 115 } 116 117 //GetPublicKey implements github.com/insolar/insolar/core.CryptographyService interface 118 func (m *CryptographyServiceMock) GetPublicKey() (r crypto.PublicKey, r1 error) { 119 counter := atomic.AddUint64(&m.GetPublicKeyPreCounter, 1) 120 defer atomic.AddUint64(&m.GetPublicKeyCounter, 1) 121 122 if len(m.GetPublicKeyMock.expectationSeries) > 0 { 123 if counter > uint64(len(m.GetPublicKeyMock.expectationSeries)) { 124 m.t.Fatalf("Unexpected call to CryptographyServiceMock.GetPublicKey.") 125 return 126 } 127 128 result := m.GetPublicKeyMock.expectationSeries[counter-1].result 129 if result == nil { 130 m.t.Fatal("No results are set for the CryptographyServiceMock.GetPublicKey") 131 return 132 } 133 134 r = result.r 135 r1 = result.r1 136 137 return 138 } 139 140 if m.GetPublicKeyMock.mainExpectation != nil { 141 142 result := m.GetPublicKeyMock.mainExpectation.result 143 if result == nil { 144 m.t.Fatal("No results are set for the CryptographyServiceMock.GetPublicKey") 145 } 146 147 r = result.r 148 r1 = result.r1 149 150 return 151 } 152 153 if m.GetPublicKeyFunc == nil { 154 m.t.Fatalf("Unexpected call to CryptographyServiceMock.GetPublicKey.") 155 return 156 } 157 158 return m.GetPublicKeyFunc() 159 } 160 161 //GetPublicKeyMinimockCounter returns a count of CryptographyServiceMock.GetPublicKeyFunc invocations 162 func (m *CryptographyServiceMock) GetPublicKeyMinimockCounter() uint64 { 163 return atomic.LoadUint64(&m.GetPublicKeyCounter) 164 } 165 166 //GetPublicKeyMinimockPreCounter returns the value of CryptographyServiceMock.GetPublicKey invocations 167 func (m *CryptographyServiceMock) GetPublicKeyMinimockPreCounter() uint64 { 168 return atomic.LoadUint64(&m.GetPublicKeyPreCounter) 169 } 170 171 //GetPublicKeyFinished returns true if mock invocations count is ok 172 func (m *CryptographyServiceMock) GetPublicKeyFinished() bool { 173 // if expectation series were set then invocations count should be equal to expectations count 174 if len(m.GetPublicKeyMock.expectationSeries) > 0 { 175 return atomic.LoadUint64(&m.GetPublicKeyCounter) == uint64(len(m.GetPublicKeyMock.expectationSeries)) 176 } 177 178 // if main expectation was set then invocations count should be greater than zero 179 if m.GetPublicKeyMock.mainExpectation != nil { 180 return atomic.LoadUint64(&m.GetPublicKeyCounter) > 0 181 } 182 183 // if func was set then invocations count should be greater than zero 184 if m.GetPublicKeyFunc != nil { 185 return atomic.LoadUint64(&m.GetPublicKeyCounter) > 0 186 } 187 188 return true 189 } 190 191 type mCryptographyServiceMockSign struct { 192 mock *CryptographyServiceMock 193 mainExpectation *CryptographyServiceMockSignExpectation 194 expectationSeries []*CryptographyServiceMockSignExpectation 195 } 196 197 type CryptographyServiceMockSignExpectation struct { 198 input *CryptographyServiceMockSignInput 199 result *CryptographyServiceMockSignResult 200 } 201 202 type CryptographyServiceMockSignInput struct { 203 p []byte 204 } 205 206 type CryptographyServiceMockSignResult struct { 207 r *core.Signature 208 r1 error 209 } 210 211 //Expect specifies that invocation of CryptographyService.Sign is expected from 1 to Infinity times 212 func (m *mCryptographyServiceMockSign) Expect(p []byte) *mCryptographyServiceMockSign { 213 m.mock.SignFunc = nil 214 m.expectationSeries = nil 215 216 if m.mainExpectation == nil { 217 m.mainExpectation = &CryptographyServiceMockSignExpectation{} 218 } 219 m.mainExpectation.input = &CryptographyServiceMockSignInput{p} 220 return m 221 } 222 223 //Return specifies results of invocation of CryptographyService.Sign 224 func (m *mCryptographyServiceMockSign) Return(r *core.Signature, r1 error) *CryptographyServiceMock { 225 m.mock.SignFunc = nil 226 m.expectationSeries = nil 227 228 if m.mainExpectation == nil { 229 m.mainExpectation = &CryptographyServiceMockSignExpectation{} 230 } 231 m.mainExpectation.result = &CryptographyServiceMockSignResult{r, r1} 232 return m.mock 233 } 234 235 //ExpectOnce specifies that invocation of CryptographyService.Sign is expected once 236 func (m *mCryptographyServiceMockSign) ExpectOnce(p []byte) *CryptographyServiceMockSignExpectation { 237 m.mock.SignFunc = nil 238 m.mainExpectation = nil 239 240 expectation := &CryptographyServiceMockSignExpectation{} 241 expectation.input = &CryptographyServiceMockSignInput{p} 242 m.expectationSeries = append(m.expectationSeries, expectation) 243 return expectation 244 } 245 246 func (e *CryptographyServiceMockSignExpectation) Return(r *core.Signature, r1 error) { 247 e.result = &CryptographyServiceMockSignResult{r, r1} 248 } 249 250 //Set uses given function f as a mock of CryptographyService.Sign method 251 func (m *mCryptographyServiceMockSign) Set(f func(p []byte) (r *core.Signature, r1 error)) *CryptographyServiceMock { 252 m.mainExpectation = nil 253 m.expectationSeries = nil 254 255 m.mock.SignFunc = f 256 return m.mock 257 } 258 259 //Sign implements github.com/insolar/insolar/core.CryptographyService interface 260 func (m *CryptographyServiceMock) Sign(p []byte) (r *core.Signature, r1 error) { 261 counter := atomic.AddUint64(&m.SignPreCounter, 1) 262 defer atomic.AddUint64(&m.SignCounter, 1) 263 264 if len(m.SignMock.expectationSeries) > 0 { 265 if counter > uint64(len(m.SignMock.expectationSeries)) { 266 m.t.Fatalf("Unexpected call to CryptographyServiceMock.Sign. %v", p) 267 return 268 } 269 270 input := m.SignMock.expectationSeries[counter-1].input 271 testify_assert.Equal(m.t, *input, CryptographyServiceMockSignInput{p}, "CryptographyService.Sign got unexpected parameters") 272 273 result := m.SignMock.expectationSeries[counter-1].result 274 if result == nil { 275 m.t.Fatal("No results are set for the CryptographyServiceMock.Sign") 276 return 277 } 278 279 r = result.r 280 r1 = result.r1 281 282 return 283 } 284 285 if m.SignMock.mainExpectation != nil { 286 287 input := m.SignMock.mainExpectation.input 288 if input != nil { 289 testify_assert.Equal(m.t, *input, CryptographyServiceMockSignInput{p}, "CryptographyService.Sign got unexpected parameters") 290 } 291 292 result := m.SignMock.mainExpectation.result 293 if result == nil { 294 m.t.Fatal("No results are set for the CryptographyServiceMock.Sign") 295 } 296 297 r = result.r 298 r1 = result.r1 299 300 return 301 } 302 303 if m.SignFunc == nil { 304 m.t.Fatalf("Unexpected call to CryptographyServiceMock.Sign. %v", p) 305 return 306 } 307 308 return m.SignFunc(p) 309 } 310 311 //SignMinimockCounter returns a count of CryptographyServiceMock.SignFunc invocations 312 func (m *CryptographyServiceMock) SignMinimockCounter() uint64 { 313 return atomic.LoadUint64(&m.SignCounter) 314 } 315 316 //SignMinimockPreCounter returns the value of CryptographyServiceMock.Sign invocations 317 func (m *CryptographyServiceMock) SignMinimockPreCounter() uint64 { 318 return atomic.LoadUint64(&m.SignPreCounter) 319 } 320 321 //SignFinished returns true if mock invocations count is ok 322 func (m *CryptographyServiceMock) SignFinished() bool { 323 // if expectation series were set then invocations count should be equal to expectations count 324 if len(m.SignMock.expectationSeries) > 0 { 325 return atomic.LoadUint64(&m.SignCounter) == uint64(len(m.SignMock.expectationSeries)) 326 } 327 328 // if main expectation was set then invocations count should be greater than zero 329 if m.SignMock.mainExpectation != nil { 330 return atomic.LoadUint64(&m.SignCounter) > 0 331 } 332 333 // if func was set then invocations count should be greater than zero 334 if m.SignFunc != nil { 335 return atomic.LoadUint64(&m.SignCounter) > 0 336 } 337 338 return true 339 } 340 341 type mCryptographyServiceMockVerify struct { 342 mock *CryptographyServiceMock 343 mainExpectation *CryptographyServiceMockVerifyExpectation 344 expectationSeries []*CryptographyServiceMockVerifyExpectation 345 } 346 347 type CryptographyServiceMockVerifyExpectation struct { 348 input *CryptographyServiceMockVerifyInput 349 result *CryptographyServiceMockVerifyResult 350 } 351 352 type CryptographyServiceMockVerifyInput struct { 353 p crypto.PublicKey 354 p1 core.Signature 355 p2 []byte 356 } 357 358 type CryptographyServiceMockVerifyResult struct { 359 r bool 360 } 361 362 //Expect specifies that invocation of CryptographyService.Verify is expected from 1 to Infinity times 363 func (m *mCryptographyServiceMockVerify) Expect(p crypto.PublicKey, p1 core.Signature, p2 []byte) *mCryptographyServiceMockVerify { 364 m.mock.VerifyFunc = nil 365 m.expectationSeries = nil 366 367 if m.mainExpectation == nil { 368 m.mainExpectation = &CryptographyServiceMockVerifyExpectation{} 369 } 370 m.mainExpectation.input = &CryptographyServiceMockVerifyInput{p, p1, p2} 371 return m 372 } 373 374 //Return specifies results of invocation of CryptographyService.Verify 375 func (m *mCryptographyServiceMockVerify) Return(r bool) *CryptographyServiceMock { 376 m.mock.VerifyFunc = nil 377 m.expectationSeries = nil 378 379 if m.mainExpectation == nil { 380 m.mainExpectation = &CryptographyServiceMockVerifyExpectation{} 381 } 382 m.mainExpectation.result = &CryptographyServiceMockVerifyResult{r} 383 return m.mock 384 } 385 386 //ExpectOnce specifies that invocation of CryptographyService.Verify is expected once 387 func (m *mCryptographyServiceMockVerify) ExpectOnce(p crypto.PublicKey, p1 core.Signature, p2 []byte) *CryptographyServiceMockVerifyExpectation { 388 m.mock.VerifyFunc = nil 389 m.mainExpectation = nil 390 391 expectation := &CryptographyServiceMockVerifyExpectation{} 392 expectation.input = &CryptographyServiceMockVerifyInput{p, p1, p2} 393 m.expectationSeries = append(m.expectationSeries, expectation) 394 return expectation 395 } 396 397 func (e *CryptographyServiceMockVerifyExpectation) Return(r bool) { 398 e.result = &CryptographyServiceMockVerifyResult{r} 399 } 400 401 //Set uses given function f as a mock of CryptographyService.Verify method 402 func (m *mCryptographyServiceMockVerify) Set(f func(p crypto.PublicKey, p1 core.Signature, p2 []byte) (r bool)) *CryptographyServiceMock { 403 m.mainExpectation = nil 404 m.expectationSeries = nil 405 406 m.mock.VerifyFunc = f 407 return m.mock 408 } 409 410 //Verify implements github.com/insolar/insolar/core.CryptographyService interface 411 func (m *CryptographyServiceMock) Verify(p crypto.PublicKey, p1 core.Signature, p2 []byte) (r bool) { 412 counter := atomic.AddUint64(&m.VerifyPreCounter, 1) 413 defer atomic.AddUint64(&m.VerifyCounter, 1) 414 415 if len(m.VerifyMock.expectationSeries) > 0 { 416 if counter > uint64(len(m.VerifyMock.expectationSeries)) { 417 m.t.Fatalf("Unexpected call to CryptographyServiceMock.Verify. %v %v %v", p, p1, p2) 418 return 419 } 420 421 input := m.VerifyMock.expectationSeries[counter-1].input 422 testify_assert.Equal(m.t, *input, CryptographyServiceMockVerifyInput{p, p1, p2}, "CryptographyService.Verify got unexpected parameters") 423 424 result := m.VerifyMock.expectationSeries[counter-1].result 425 if result == nil { 426 m.t.Fatal("No results are set for the CryptographyServiceMock.Verify") 427 return 428 } 429 430 r = result.r 431 432 return 433 } 434 435 if m.VerifyMock.mainExpectation != nil { 436 437 input := m.VerifyMock.mainExpectation.input 438 if input != nil { 439 testify_assert.Equal(m.t, *input, CryptographyServiceMockVerifyInput{p, p1, p2}, "CryptographyService.Verify got unexpected parameters") 440 } 441 442 result := m.VerifyMock.mainExpectation.result 443 if result == nil { 444 m.t.Fatal("No results are set for the CryptographyServiceMock.Verify") 445 } 446 447 r = result.r 448 449 return 450 } 451 452 if m.VerifyFunc == nil { 453 m.t.Fatalf("Unexpected call to CryptographyServiceMock.Verify. %v %v %v", p, p1, p2) 454 return 455 } 456 457 return m.VerifyFunc(p, p1, p2) 458 } 459 460 //VerifyMinimockCounter returns a count of CryptographyServiceMock.VerifyFunc invocations 461 func (m *CryptographyServiceMock) VerifyMinimockCounter() uint64 { 462 return atomic.LoadUint64(&m.VerifyCounter) 463 } 464 465 //VerifyMinimockPreCounter returns the value of CryptographyServiceMock.Verify invocations 466 func (m *CryptographyServiceMock) VerifyMinimockPreCounter() uint64 { 467 return atomic.LoadUint64(&m.VerifyPreCounter) 468 } 469 470 //VerifyFinished returns true if mock invocations count is ok 471 func (m *CryptographyServiceMock) VerifyFinished() bool { 472 // if expectation series were set then invocations count should be equal to expectations count 473 if len(m.VerifyMock.expectationSeries) > 0 { 474 return atomic.LoadUint64(&m.VerifyCounter) == uint64(len(m.VerifyMock.expectationSeries)) 475 } 476 477 // if main expectation was set then invocations count should be greater than zero 478 if m.VerifyMock.mainExpectation != nil { 479 return atomic.LoadUint64(&m.VerifyCounter) > 0 480 } 481 482 // if func was set then invocations count should be greater than zero 483 if m.VerifyFunc != nil { 484 return atomic.LoadUint64(&m.VerifyCounter) > 0 485 } 486 487 return true 488 } 489 490 //ValidateCallCounters checks that all mocked methods of the interface have been called at least once 491 //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller 492 func (m *CryptographyServiceMock) ValidateCallCounters() { 493 494 if !m.GetPublicKeyFinished() { 495 m.t.Fatal("Expected call to CryptographyServiceMock.GetPublicKey") 496 } 497 498 if !m.SignFinished() { 499 m.t.Fatal("Expected call to CryptographyServiceMock.Sign") 500 } 501 502 if !m.VerifyFinished() { 503 m.t.Fatal("Expected call to CryptographyServiceMock.Verify") 504 } 505 506 } 507 508 //CheckMocksCalled checks that all mocked methods of the interface have been called at least once 509 //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller 510 func (m *CryptographyServiceMock) CheckMocksCalled() { 511 m.Finish() 512 } 513 514 //Finish checks that all mocked methods of the interface have been called at least once 515 //Deprecated: please use MinimockFinish or use Finish method of minimock.Controller 516 func (m *CryptographyServiceMock) Finish() { 517 m.MinimockFinish() 518 } 519 520 //MinimockFinish checks that all mocked methods of the interface have been called at least once 521 func (m *CryptographyServiceMock) MinimockFinish() { 522 523 if !m.GetPublicKeyFinished() { 524 m.t.Fatal("Expected call to CryptographyServiceMock.GetPublicKey") 525 } 526 527 if !m.SignFinished() { 528 m.t.Fatal("Expected call to CryptographyServiceMock.Sign") 529 } 530 531 if !m.VerifyFinished() { 532 m.t.Fatal("Expected call to CryptographyServiceMock.Verify") 533 } 534 535 } 536 537 //Wait waits for all mocked methods to be called at least once 538 //Deprecated: please use MinimockWait or use Wait method of minimock.Controller 539 func (m *CryptographyServiceMock) Wait(timeout time.Duration) { 540 m.MinimockWait(timeout) 541 } 542 543 //MinimockWait waits for all mocked methods to be called at least once 544 //this method is called by minimock.Controller 545 func (m *CryptographyServiceMock) MinimockWait(timeout time.Duration) { 546 timeoutCh := time.After(timeout) 547 for { 548 ok := true 549 ok = ok && m.GetPublicKeyFinished() 550 ok = ok && m.SignFinished() 551 ok = ok && m.VerifyFinished() 552 553 if ok { 554 return 555 } 556 557 select { 558 case <-timeoutCh: 559 560 if !m.GetPublicKeyFinished() { 561 m.t.Error("Expected call to CryptographyServiceMock.GetPublicKey") 562 } 563 564 if !m.SignFinished() { 565 m.t.Error("Expected call to CryptographyServiceMock.Sign") 566 } 567 568 if !m.VerifyFinished() { 569 m.t.Error("Expected call to CryptographyServiceMock.Verify") 570 } 571 572 m.t.Fatalf("Some mocks were not called on time: %s", timeout) 573 return 574 default: 575 time.Sleep(time.Millisecond) 576 } 577 } 578 } 579 580 //AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled, 581 //it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled()) 582 func (m *CryptographyServiceMock) AllMocksCalled() bool { 583 584 if !m.GetPublicKeyFinished() { 585 return false 586 } 587 588 if !m.SignFinished() { 589 return false 590 } 591 592 if !m.VerifyFinished() { 593 return false 594 } 595 596 return true 597 }