github.com/braveheart12/insolar-09-08-19@v0.8.7/testutils/network/node_mock.go (about) 1 package network 2 3 /* 4 DO NOT EDIT! 5 This code was generated automatically using github.com/gojuno/minimock v1.9 6 The original interface "Node" 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 17 //NodeMock implements github.com/insolar/insolar/core.Node 18 type NodeMock struct { 19 t minimock.Tester 20 21 AddressFunc func() (r string) 22 AddressCounter uint64 23 AddressPreCounter uint64 24 AddressMock mNodeMockAddress 25 26 ConsensusAddressFunc func() (r string) 27 ConsensusAddressCounter uint64 28 ConsensusAddressPreCounter uint64 29 ConsensusAddressMock mNodeMockConsensusAddress 30 31 GetGlobuleIDFunc func() (r core.GlobuleID) 32 GetGlobuleIDCounter uint64 33 GetGlobuleIDPreCounter uint64 34 GetGlobuleIDMock mNodeMockGetGlobuleID 35 36 GetStateFunc func() (r core.NodeState) 37 GetStateCounter uint64 38 GetStatePreCounter uint64 39 GetStateMock mNodeMockGetState 40 41 IDFunc func() (r core.RecordRef) 42 IDCounter uint64 43 IDPreCounter uint64 44 IDMock mNodeMockID 45 46 IsWorkingFunc func() (r bool) 47 IsWorkingCounter uint64 48 IsWorkingPreCounter uint64 49 IsWorkingMock mNodeMockIsWorking 50 51 LeavingFunc func() (r bool) 52 LeavingCounter uint64 53 LeavingPreCounter uint64 54 LeavingMock mNodeMockLeaving 55 56 LeavingETAFunc func() (r core.PulseNumber) 57 LeavingETACounter uint64 58 LeavingETAPreCounter uint64 59 LeavingETAMock mNodeMockLeavingETA 60 61 PublicKeyFunc func() (r crypto.PublicKey) 62 PublicKeyCounter uint64 63 PublicKeyPreCounter uint64 64 PublicKeyMock mNodeMockPublicKey 65 66 RoleFunc func() (r core.StaticRole) 67 RoleCounter uint64 68 RolePreCounter uint64 69 RoleMock mNodeMockRole 70 71 ShortIDFunc func() (r core.ShortNodeID) 72 ShortIDCounter uint64 73 ShortIDPreCounter uint64 74 ShortIDMock mNodeMockShortID 75 76 VersionFunc func() (r string) 77 VersionCounter uint64 78 VersionPreCounter uint64 79 VersionMock mNodeMockVersion 80 } 81 82 //NewNodeMock returns a mock for github.com/insolar/insolar/core.Node 83 func NewNodeMock(t minimock.Tester) *NodeMock { 84 m := &NodeMock{t: t} 85 86 if controller, ok := t.(minimock.MockController); ok { 87 controller.RegisterMocker(m) 88 } 89 90 m.AddressMock = mNodeMockAddress{mock: m} 91 m.ConsensusAddressMock = mNodeMockConsensusAddress{mock: m} 92 m.GetGlobuleIDMock = mNodeMockGetGlobuleID{mock: m} 93 m.GetStateMock = mNodeMockGetState{mock: m} 94 m.IDMock = mNodeMockID{mock: m} 95 m.IsWorkingMock = mNodeMockIsWorking{mock: m} 96 m.LeavingMock = mNodeMockLeaving{mock: m} 97 m.LeavingETAMock = mNodeMockLeavingETA{mock: m} 98 m.PublicKeyMock = mNodeMockPublicKey{mock: m} 99 m.RoleMock = mNodeMockRole{mock: m} 100 m.ShortIDMock = mNodeMockShortID{mock: m} 101 m.VersionMock = mNodeMockVersion{mock: m} 102 103 return m 104 } 105 106 type mNodeMockAddress struct { 107 mock *NodeMock 108 mainExpectation *NodeMockAddressExpectation 109 expectationSeries []*NodeMockAddressExpectation 110 } 111 112 type NodeMockAddressExpectation struct { 113 result *NodeMockAddressResult 114 } 115 116 type NodeMockAddressResult struct { 117 r string 118 } 119 120 //Expect specifies that invocation of Node.Address is expected from 1 to Infinity times 121 func (m *mNodeMockAddress) Expect() *mNodeMockAddress { 122 m.mock.AddressFunc = nil 123 m.expectationSeries = nil 124 125 if m.mainExpectation == nil { 126 m.mainExpectation = &NodeMockAddressExpectation{} 127 } 128 129 return m 130 } 131 132 //Return specifies results of invocation of Node.Address 133 func (m *mNodeMockAddress) Return(r string) *NodeMock { 134 m.mock.AddressFunc = nil 135 m.expectationSeries = nil 136 137 if m.mainExpectation == nil { 138 m.mainExpectation = &NodeMockAddressExpectation{} 139 } 140 m.mainExpectation.result = &NodeMockAddressResult{r} 141 return m.mock 142 } 143 144 //ExpectOnce specifies that invocation of Node.Address is expected once 145 func (m *mNodeMockAddress) ExpectOnce() *NodeMockAddressExpectation { 146 m.mock.AddressFunc = nil 147 m.mainExpectation = nil 148 149 expectation := &NodeMockAddressExpectation{} 150 151 m.expectationSeries = append(m.expectationSeries, expectation) 152 return expectation 153 } 154 155 func (e *NodeMockAddressExpectation) Return(r string) { 156 e.result = &NodeMockAddressResult{r} 157 } 158 159 //Set uses given function f as a mock of Node.Address method 160 func (m *mNodeMockAddress) Set(f func() (r string)) *NodeMock { 161 m.mainExpectation = nil 162 m.expectationSeries = nil 163 164 m.mock.AddressFunc = f 165 return m.mock 166 } 167 168 //Address implements github.com/insolar/insolar/core.Node interface 169 func (m *NodeMock) Address() (r string) { 170 counter := atomic.AddUint64(&m.AddressPreCounter, 1) 171 defer atomic.AddUint64(&m.AddressCounter, 1) 172 173 if len(m.AddressMock.expectationSeries) > 0 { 174 if counter > uint64(len(m.AddressMock.expectationSeries)) { 175 m.t.Fatalf("Unexpected call to NodeMock.Address.") 176 return 177 } 178 179 result := m.AddressMock.expectationSeries[counter-1].result 180 if result == nil { 181 m.t.Fatal("No results are set for the NodeMock.Address") 182 return 183 } 184 185 r = result.r 186 187 return 188 } 189 190 if m.AddressMock.mainExpectation != nil { 191 192 result := m.AddressMock.mainExpectation.result 193 if result == nil { 194 m.t.Fatal("No results are set for the NodeMock.Address") 195 } 196 197 r = result.r 198 199 return 200 } 201 202 if m.AddressFunc == nil { 203 m.t.Fatalf("Unexpected call to NodeMock.Address.") 204 return 205 } 206 207 return m.AddressFunc() 208 } 209 210 //AddressMinimockCounter returns a count of NodeMock.AddressFunc invocations 211 func (m *NodeMock) AddressMinimockCounter() uint64 { 212 return atomic.LoadUint64(&m.AddressCounter) 213 } 214 215 //AddressMinimockPreCounter returns the value of NodeMock.Address invocations 216 func (m *NodeMock) AddressMinimockPreCounter() uint64 { 217 return atomic.LoadUint64(&m.AddressPreCounter) 218 } 219 220 //AddressFinished returns true if mock invocations count is ok 221 func (m *NodeMock) AddressFinished() bool { 222 // if expectation series were set then invocations count should be equal to expectations count 223 if len(m.AddressMock.expectationSeries) > 0 { 224 return atomic.LoadUint64(&m.AddressCounter) == uint64(len(m.AddressMock.expectationSeries)) 225 } 226 227 // if main expectation was set then invocations count should be greater than zero 228 if m.AddressMock.mainExpectation != nil { 229 return atomic.LoadUint64(&m.AddressCounter) > 0 230 } 231 232 // if func was set then invocations count should be greater than zero 233 if m.AddressFunc != nil { 234 return atomic.LoadUint64(&m.AddressCounter) > 0 235 } 236 237 return true 238 } 239 240 type mNodeMockConsensusAddress struct { 241 mock *NodeMock 242 mainExpectation *NodeMockConsensusAddressExpectation 243 expectationSeries []*NodeMockConsensusAddressExpectation 244 } 245 246 type NodeMockConsensusAddressExpectation struct { 247 result *NodeMockConsensusAddressResult 248 } 249 250 type NodeMockConsensusAddressResult struct { 251 r string 252 } 253 254 //Expect specifies that invocation of Node.ConsensusAddress is expected from 1 to Infinity times 255 func (m *mNodeMockConsensusAddress) Expect() *mNodeMockConsensusAddress { 256 m.mock.ConsensusAddressFunc = nil 257 m.expectationSeries = nil 258 259 if m.mainExpectation == nil { 260 m.mainExpectation = &NodeMockConsensusAddressExpectation{} 261 } 262 263 return m 264 } 265 266 //Return specifies results of invocation of Node.ConsensusAddress 267 func (m *mNodeMockConsensusAddress) Return(r string) *NodeMock { 268 m.mock.ConsensusAddressFunc = nil 269 m.expectationSeries = nil 270 271 if m.mainExpectation == nil { 272 m.mainExpectation = &NodeMockConsensusAddressExpectation{} 273 } 274 m.mainExpectation.result = &NodeMockConsensusAddressResult{r} 275 return m.mock 276 } 277 278 //ExpectOnce specifies that invocation of Node.ConsensusAddress is expected once 279 func (m *mNodeMockConsensusAddress) ExpectOnce() *NodeMockConsensusAddressExpectation { 280 m.mock.ConsensusAddressFunc = nil 281 m.mainExpectation = nil 282 283 expectation := &NodeMockConsensusAddressExpectation{} 284 285 m.expectationSeries = append(m.expectationSeries, expectation) 286 return expectation 287 } 288 289 func (e *NodeMockConsensusAddressExpectation) Return(r string) { 290 e.result = &NodeMockConsensusAddressResult{r} 291 } 292 293 //Set uses given function f as a mock of Node.ConsensusAddress method 294 func (m *mNodeMockConsensusAddress) Set(f func() (r string)) *NodeMock { 295 m.mainExpectation = nil 296 m.expectationSeries = nil 297 298 m.mock.ConsensusAddressFunc = f 299 return m.mock 300 } 301 302 //ConsensusAddress implements github.com/insolar/insolar/core.Node interface 303 func (m *NodeMock) ConsensusAddress() (r string) { 304 counter := atomic.AddUint64(&m.ConsensusAddressPreCounter, 1) 305 defer atomic.AddUint64(&m.ConsensusAddressCounter, 1) 306 307 if len(m.ConsensusAddressMock.expectationSeries) > 0 { 308 if counter > uint64(len(m.ConsensusAddressMock.expectationSeries)) { 309 m.t.Fatalf("Unexpected call to NodeMock.ConsensusAddress.") 310 return 311 } 312 313 result := m.ConsensusAddressMock.expectationSeries[counter-1].result 314 if result == nil { 315 m.t.Fatal("No results are set for the NodeMock.ConsensusAddress") 316 return 317 } 318 319 r = result.r 320 321 return 322 } 323 324 if m.ConsensusAddressMock.mainExpectation != nil { 325 326 result := m.ConsensusAddressMock.mainExpectation.result 327 if result == nil { 328 m.t.Fatal("No results are set for the NodeMock.ConsensusAddress") 329 } 330 331 r = result.r 332 333 return 334 } 335 336 if m.ConsensusAddressFunc == nil { 337 m.t.Fatalf("Unexpected call to NodeMock.ConsensusAddress.") 338 return 339 } 340 341 return m.ConsensusAddressFunc() 342 } 343 344 //ConsensusAddressMinimockCounter returns a count of NodeMock.ConsensusAddressFunc invocations 345 func (m *NodeMock) ConsensusAddressMinimockCounter() uint64 { 346 return atomic.LoadUint64(&m.ConsensusAddressCounter) 347 } 348 349 //ConsensusAddressMinimockPreCounter returns the value of NodeMock.ConsensusAddress invocations 350 func (m *NodeMock) ConsensusAddressMinimockPreCounter() uint64 { 351 return atomic.LoadUint64(&m.ConsensusAddressPreCounter) 352 } 353 354 //ConsensusAddressFinished returns true if mock invocations count is ok 355 func (m *NodeMock) ConsensusAddressFinished() bool { 356 // if expectation series were set then invocations count should be equal to expectations count 357 if len(m.ConsensusAddressMock.expectationSeries) > 0 { 358 return atomic.LoadUint64(&m.ConsensusAddressCounter) == uint64(len(m.ConsensusAddressMock.expectationSeries)) 359 } 360 361 // if main expectation was set then invocations count should be greater than zero 362 if m.ConsensusAddressMock.mainExpectation != nil { 363 return atomic.LoadUint64(&m.ConsensusAddressCounter) > 0 364 } 365 366 // if func was set then invocations count should be greater than zero 367 if m.ConsensusAddressFunc != nil { 368 return atomic.LoadUint64(&m.ConsensusAddressCounter) > 0 369 } 370 371 return true 372 } 373 374 type mNodeMockGetGlobuleID struct { 375 mock *NodeMock 376 mainExpectation *NodeMockGetGlobuleIDExpectation 377 expectationSeries []*NodeMockGetGlobuleIDExpectation 378 } 379 380 type NodeMockGetGlobuleIDExpectation struct { 381 result *NodeMockGetGlobuleIDResult 382 } 383 384 type NodeMockGetGlobuleIDResult struct { 385 r core.GlobuleID 386 } 387 388 //Expect specifies that invocation of Node.GetGlobuleID is expected from 1 to Infinity times 389 func (m *mNodeMockGetGlobuleID) Expect() *mNodeMockGetGlobuleID { 390 m.mock.GetGlobuleIDFunc = nil 391 m.expectationSeries = nil 392 393 if m.mainExpectation == nil { 394 m.mainExpectation = &NodeMockGetGlobuleIDExpectation{} 395 } 396 397 return m 398 } 399 400 //Return specifies results of invocation of Node.GetGlobuleID 401 func (m *mNodeMockGetGlobuleID) Return(r core.GlobuleID) *NodeMock { 402 m.mock.GetGlobuleIDFunc = nil 403 m.expectationSeries = nil 404 405 if m.mainExpectation == nil { 406 m.mainExpectation = &NodeMockGetGlobuleIDExpectation{} 407 } 408 m.mainExpectation.result = &NodeMockGetGlobuleIDResult{r} 409 return m.mock 410 } 411 412 //ExpectOnce specifies that invocation of Node.GetGlobuleID is expected once 413 func (m *mNodeMockGetGlobuleID) ExpectOnce() *NodeMockGetGlobuleIDExpectation { 414 m.mock.GetGlobuleIDFunc = nil 415 m.mainExpectation = nil 416 417 expectation := &NodeMockGetGlobuleIDExpectation{} 418 419 m.expectationSeries = append(m.expectationSeries, expectation) 420 return expectation 421 } 422 423 func (e *NodeMockGetGlobuleIDExpectation) Return(r core.GlobuleID) { 424 e.result = &NodeMockGetGlobuleIDResult{r} 425 } 426 427 //Set uses given function f as a mock of Node.GetGlobuleID method 428 func (m *mNodeMockGetGlobuleID) Set(f func() (r core.GlobuleID)) *NodeMock { 429 m.mainExpectation = nil 430 m.expectationSeries = nil 431 432 m.mock.GetGlobuleIDFunc = f 433 return m.mock 434 } 435 436 //GetGlobuleID implements github.com/insolar/insolar/core.Node interface 437 func (m *NodeMock) GetGlobuleID() (r core.GlobuleID) { 438 counter := atomic.AddUint64(&m.GetGlobuleIDPreCounter, 1) 439 defer atomic.AddUint64(&m.GetGlobuleIDCounter, 1) 440 441 if len(m.GetGlobuleIDMock.expectationSeries) > 0 { 442 if counter > uint64(len(m.GetGlobuleIDMock.expectationSeries)) { 443 m.t.Fatalf("Unexpected call to NodeMock.GetGlobuleID.") 444 return 445 } 446 447 result := m.GetGlobuleIDMock.expectationSeries[counter-1].result 448 if result == nil { 449 m.t.Fatal("No results are set for the NodeMock.GetGlobuleID") 450 return 451 } 452 453 r = result.r 454 455 return 456 } 457 458 if m.GetGlobuleIDMock.mainExpectation != nil { 459 460 result := m.GetGlobuleIDMock.mainExpectation.result 461 if result == nil { 462 m.t.Fatal("No results are set for the NodeMock.GetGlobuleID") 463 } 464 465 r = result.r 466 467 return 468 } 469 470 if m.GetGlobuleIDFunc == nil { 471 m.t.Fatalf("Unexpected call to NodeMock.GetGlobuleID.") 472 return 473 } 474 475 return m.GetGlobuleIDFunc() 476 } 477 478 //GetGlobuleIDMinimockCounter returns a count of NodeMock.GetGlobuleIDFunc invocations 479 func (m *NodeMock) GetGlobuleIDMinimockCounter() uint64 { 480 return atomic.LoadUint64(&m.GetGlobuleIDCounter) 481 } 482 483 //GetGlobuleIDMinimockPreCounter returns the value of NodeMock.GetGlobuleID invocations 484 func (m *NodeMock) GetGlobuleIDMinimockPreCounter() uint64 { 485 return atomic.LoadUint64(&m.GetGlobuleIDPreCounter) 486 } 487 488 //GetGlobuleIDFinished returns true if mock invocations count is ok 489 func (m *NodeMock) GetGlobuleIDFinished() bool { 490 // if expectation series were set then invocations count should be equal to expectations count 491 if len(m.GetGlobuleIDMock.expectationSeries) > 0 { 492 return atomic.LoadUint64(&m.GetGlobuleIDCounter) == uint64(len(m.GetGlobuleIDMock.expectationSeries)) 493 } 494 495 // if main expectation was set then invocations count should be greater than zero 496 if m.GetGlobuleIDMock.mainExpectation != nil { 497 return atomic.LoadUint64(&m.GetGlobuleIDCounter) > 0 498 } 499 500 // if func was set then invocations count should be greater than zero 501 if m.GetGlobuleIDFunc != nil { 502 return atomic.LoadUint64(&m.GetGlobuleIDCounter) > 0 503 } 504 505 return true 506 } 507 508 type mNodeMockGetState struct { 509 mock *NodeMock 510 mainExpectation *NodeMockGetStateExpectation 511 expectationSeries []*NodeMockGetStateExpectation 512 } 513 514 type NodeMockGetStateExpectation struct { 515 result *NodeMockGetStateResult 516 } 517 518 type NodeMockGetStateResult struct { 519 r core.NodeState 520 } 521 522 //Expect specifies that invocation of Node.GetState is expected from 1 to Infinity times 523 func (m *mNodeMockGetState) Expect() *mNodeMockGetState { 524 m.mock.GetStateFunc = nil 525 m.expectationSeries = nil 526 527 if m.mainExpectation == nil { 528 m.mainExpectation = &NodeMockGetStateExpectation{} 529 } 530 531 return m 532 } 533 534 //Return specifies results of invocation of Node.GetState 535 func (m *mNodeMockGetState) Return(r core.NodeState) *NodeMock { 536 m.mock.GetStateFunc = nil 537 m.expectationSeries = nil 538 539 if m.mainExpectation == nil { 540 m.mainExpectation = &NodeMockGetStateExpectation{} 541 } 542 m.mainExpectation.result = &NodeMockGetStateResult{r} 543 return m.mock 544 } 545 546 //ExpectOnce specifies that invocation of Node.GetState is expected once 547 func (m *mNodeMockGetState) ExpectOnce() *NodeMockGetStateExpectation { 548 m.mock.GetStateFunc = nil 549 m.mainExpectation = nil 550 551 expectation := &NodeMockGetStateExpectation{} 552 553 m.expectationSeries = append(m.expectationSeries, expectation) 554 return expectation 555 } 556 557 func (e *NodeMockGetStateExpectation) Return(r core.NodeState) { 558 e.result = &NodeMockGetStateResult{r} 559 } 560 561 //Set uses given function f as a mock of Node.GetState method 562 func (m *mNodeMockGetState) Set(f func() (r core.NodeState)) *NodeMock { 563 m.mainExpectation = nil 564 m.expectationSeries = nil 565 566 m.mock.GetStateFunc = f 567 return m.mock 568 } 569 570 //GetState implements github.com/insolar/insolar/core.Node interface 571 func (m *NodeMock) GetState() (r core.NodeState) { 572 counter := atomic.AddUint64(&m.GetStatePreCounter, 1) 573 defer atomic.AddUint64(&m.GetStateCounter, 1) 574 575 if len(m.GetStateMock.expectationSeries) > 0 { 576 if counter > uint64(len(m.GetStateMock.expectationSeries)) { 577 m.t.Fatalf("Unexpected call to NodeMock.GetState.") 578 return 579 } 580 581 result := m.GetStateMock.expectationSeries[counter-1].result 582 if result == nil { 583 m.t.Fatal("No results are set for the NodeMock.GetState") 584 return 585 } 586 587 r = result.r 588 589 return 590 } 591 592 if m.GetStateMock.mainExpectation != nil { 593 594 result := m.GetStateMock.mainExpectation.result 595 if result == nil { 596 m.t.Fatal("No results are set for the NodeMock.GetState") 597 } 598 599 r = result.r 600 601 return 602 } 603 604 if m.GetStateFunc == nil { 605 m.t.Fatalf("Unexpected call to NodeMock.GetState.") 606 return 607 } 608 609 return m.GetStateFunc() 610 } 611 612 //GetStateMinimockCounter returns a count of NodeMock.GetStateFunc invocations 613 func (m *NodeMock) GetStateMinimockCounter() uint64 { 614 return atomic.LoadUint64(&m.GetStateCounter) 615 } 616 617 //GetStateMinimockPreCounter returns the value of NodeMock.GetState invocations 618 func (m *NodeMock) GetStateMinimockPreCounter() uint64 { 619 return atomic.LoadUint64(&m.GetStatePreCounter) 620 } 621 622 //GetStateFinished returns true if mock invocations count is ok 623 func (m *NodeMock) GetStateFinished() bool { 624 // if expectation series were set then invocations count should be equal to expectations count 625 if len(m.GetStateMock.expectationSeries) > 0 { 626 return atomic.LoadUint64(&m.GetStateCounter) == uint64(len(m.GetStateMock.expectationSeries)) 627 } 628 629 // if main expectation was set then invocations count should be greater than zero 630 if m.GetStateMock.mainExpectation != nil { 631 return atomic.LoadUint64(&m.GetStateCounter) > 0 632 } 633 634 // if func was set then invocations count should be greater than zero 635 if m.GetStateFunc != nil { 636 return atomic.LoadUint64(&m.GetStateCounter) > 0 637 } 638 639 return true 640 } 641 642 type mNodeMockID struct { 643 mock *NodeMock 644 mainExpectation *NodeMockIDExpectation 645 expectationSeries []*NodeMockIDExpectation 646 } 647 648 type NodeMockIDExpectation struct { 649 result *NodeMockIDResult 650 } 651 652 type NodeMockIDResult struct { 653 r core.RecordRef 654 } 655 656 //Expect specifies that invocation of Node.ID is expected from 1 to Infinity times 657 func (m *mNodeMockID) Expect() *mNodeMockID { 658 m.mock.IDFunc = nil 659 m.expectationSeries = nil 660 661 if m.mainExpectation == nil { 662 m.mainExpectation = &NodeMockIDExpectation{} 663 } 664 665 return m 666 } 667 668 //Return specifies results of invocation of Node.ID 669 func (m *mNodeMockID) Return(r core.RecordRef) *NodeMock { 670 m.mock.IDFunc = nil 671 m.expectationSeries = nil 672 673 if m.mainExpectation == nil { 674 m.mainExpectation = &NodeMockIDExpectation{} 675 } 676 m.mainExpectation.result = &NodeMockIDResult{r} 677 return m.mock 678 } 679 680 //ExpectOnce specifies that invocation of Node.ID is expected once 681 func (m *mNodeMockID) ExpectOnce() *NodeMockIDExpectation { 682 m.mock.IDFunc = nil 683 m.mainExpectation = nil 684 685 expectation := &NodeMockIDExpectation{} 686 687 m.expectationSeries = append(m.expectationSeries, expectation) 688 return expectation 689 } 690 691 func (e *NodeMockIDExpectation) Return(r core.RecordRef) { 692 e.result = &NodeMockIDResult{r} 693 } 694 695 //Set uses given function f as a mock of Node.ID method 696 func (m *mNodeMockID) Set(f func() (r core.RecordRef)) *NodeMock { 697 m.mainExpectation = nil 698 m.expectationSeries = nil 699 700 m.mock.IDFunc = f 701 return m.mock 702 } 703 704 //ID implements github.com/insolar/insolar/core.Node interface 705 func (m *NodeMock) ID() (r core.RecordRef) { 706 counter := atomic.AddUint64(&m.IDPreCounter, 1) 707 defer atomic.AddUint64(&m.IDCounter, 1) 708 709 if len(m.IDMock.expectationSeries) > 0 { 710 if counter > uint64(len(m.IDMock.expectationSeries)) { 711 m.t.Fatalf("Unexpected call to NodeMock.ID.") 712 return 713 } 714 715 result := m.IDMock.expectationSeries[counter-1].result 716 if result == nil { 717 m.t.Fatal("No results are set for the NodeMock.ID") 718 return 719 } 720 721 r = result.r 722 723 return 724 } 725 726 if m.IDMock.mainExpectation != nil { 727 728 result := m.IDMock.mainExpectation.result 729 if result == nil { 730 m.t.Fatal("No results are set for the NodeMock.ID") 731 } 732 733 r = result.r 734 735 return 736 } 737 738 if m.IDFunc == nil { 739 m.t.Fatalf("Unexpected call to NodeMock.ID.") 740 return 741 } 742 743 return m.IDFunc() 744 } 745 746 //IDMinimockCounter returns a count of NodeMock.IDFunc invocations 747 func (m *NodeMock) IDMinimockCounter() uint64 { 748 return atomic.LoadUint64(&m.IDCounter) 749 } 750 751 //IDMinimockPreCounter returns the value of NodeMock.ID invocations 752 func (m *NodeMock) IDMinimockPreCounter() uint64 { 753 return atomic.LoadUint64(&m.IDPreCounter) 754 } 755 756 //IDFinished returns true if mock invocations count is ok 757 func (m *NodeMock) IDFinished() bool { 758 // if expectation series were set then invocations count should be equal to expectations count 759 if len(m.IDMock.expectationSeries) > 0 { 760 return atomic.LoadUint64(&m.IDCounter) == uint64(len(m.IDMock.expectationSeries)) 761 } 762 763 // if main expectation was set then invocations count should be greater than zero 764 if m.IDMock.mainExpectation != nil { 765 return atomic.LoadUint64(&m.IDCounter) > 0 766 } 767 768 // if func was set then invocations count should be greater than zero 769 if m.IDFunc != nil { 770 return atomic.LoadUint64(&m.IDCounter) > 0 771 } 772 773 return true 774 } 775 776 type mNodeMockIsWorking struct { 777 mock *NodeMock 778 mainExpectation *NodeMockIsWorkingExpectation 779 expectationSeries []*NodeMockIsWorkingExpectation 780 } 781 782 type NodeMockIsWorkingExpectation struct { 783 result *NodeMockIsWorkingResult 784 } 785 786 type NodeMockIsWorkingResult struct { 787 r bool 788 } 789 790 //Expect specifies that invocation of Node.IsWorking is expected from 1 to Infinity times 791 func (m *mNodeMockIsWorking) Expect() *mNodeMockIsWorking { 792 m.mock.IsWorkingFunc = nil 793 m.expectationSeries = nil 794 795 if m.mainExpectation == nil { 796 m.mainExpectation = &NodeMockIsWorkingExpectation{} 797 } 798 799 return m 800 } 801 802 //Return specifies results of invocation of Node.IsWorking 803 func (m *mNodeMockIsWorking) Return(r bool) *NodeMock { 804 m.mock.IsWorkingFunc = nil 805 m.expectationSeries = nil 806 807 if m.mainExpectation == nil { 808 m.mainExpectation = &NodeMockIsWorkingExpectation{} 809 } 810 m.mainExpectation.result = &NodeMockIsWorkingResult{r} 811 return m.mock 812 } 813 814 //ExpectOnce specifies that invocation of Node.IsWorking is expected once 815 func (m *mNodeMockIsWorking) ExpectOnce() *NodeMockIsWorkingExpectation { 816 m.mock.IsWorkingFunc = nil 817 m.mainExpectation = nil 818 819 expectation := &NodeMockIsWorkingExpectation{} 820 821 m.expectationSeries = append(m.expectationSeries, expectation) 822 return expectation 823 } 824 825 func (e *NodeMockIsWorkingExpectation) Return(r bool) { 826 e.result = &NodeMockIsWorkingResult{r} 827 } 828 829 //Set uses given function f as a mock of Node.IsWorking method 830 func (m *mNodeMockIsWorking) Set(f func() (r bool)) *NodeMock { 831 m.mainExpectation = nil 832 m.expectationSeries = nil 833 834 m.mock.IsWorkingFunc = f 835 return m.mock 836 } 837 838 //IsWorking implements github.com/insolar/insolar/core.Node interface 839 func (m *NodeMock) IsWorking() (r bool) { 840 counter := atomic.AddUint64(&m.IsWorkingPreCounter, 1) 841 defer atomic.AddUint64(&m.IsWorkingCounter, 1) 842 843 if len(m.IsWorkingMock.expectationSeries) > 0 { 844 if counter > uint64(len(m.IsWorkingMock.expectationSeries)) { 845 m.t.Fatalf("Unexpected call to NodeMock.IsWorking.") 846 return 847 } 848 849 result := m.IsWorkingMock.expectationSeries[counter-1].result 850 if result == nil { 851 m.t.Fatal("No results are set for the NodeMock.IsWorking") 852 return 853 } 854 855 r = result.r 856 857 return 858 } 859 860 if m.IsWorkingMock.mainExpectation != nil { 861 862 result := m.IsWorkingMock.mainExpectation.result 863 if result == nil { 864 m.t.Fatal("No results are set for the NodeMock.IsWorking") 865 } 866 867 r = result.r 868 869 return 870 } 871 872 if m.IsWorkingFunc == nil { 873 m.t.Fatalf("Unexpected call to NodeMock.IsWorking.") 874 return 875 } 876 877 return m.IsWorkingFunc() 878 } 879 880 //IsWorkingMinimockCounter returns a count of NodeMock.IsWorkingFunc invocations 881 func (m *NodeMock) IsWorkingMinimockCounter() uint64 { 882 return atomic.LoadUint64(&m.IsWorkingCounter) 883 } 884 885 //IsWorkingMinimockPreCounter returns the value of NodeMock.IsWorking invocations 886 func (m *NodeMock) IsWorkingMinimockPreCounter() uint64 { 887 return atomic.LoadUint64(&m.IsWorkingPreCounter) 888 } 889 890 //IsWorkingFinished returns true if mock invocations count is ok 891 func (m *NodeMock) IsWorkingFinished() bool { 892 // if expectation series were set then invocations count should be equal to expectations count 893 if len(m.IsWorkingMock.expectationSeries) > 0 { 894 return atomic.LoadUint64(&m.IsWorkingCounter) == uint64(len(m.IsWorkingMock.expectationSeries)) 895 } 896 897 // if main expectation was set then invocations count should be greater than zero 898 if m.IsWorkingMock.mainExpectation != nil { 899 return atomic.LoadUint64(&m.IsWorkingCounter) > 0 900 } 901 902 // if func was set then invocations count should be greater than zero 903 if m.IsWorkingFunc != nil { 904 return atomic.LoadUint64(&m.IsWorkingCounter) > 0 905 } 906 907 return true 908 } 909 910 type mNodeMockLeaving struct { 911 mock *NodeMock 912 mainExpectation *NodeMockLeavingExpectation 913 expectationSeries []*NodeMockLeavingExpectation 914 } 915 916 type NodeMockLeavingExpectation struct { 917 result *NodeMockLeavingResult 918 } 919 920 type NodeMockLeavingResult struct { 921 r bool 922 } 923 924 //Expect specifies that invocation of Node.Leaving is expected from 1 to Infinity times 925 func (m *mNodeMockLeaving) Expect() *mNodeMockLeaving { 926 m.mock.LeavingFunc = nil 927 m.expectationSeries = nil 928 929 if m.mainExpectation == nil { 930 m.mainExpectation = &NodeMockLeavingExpectation{} 931 } 932 933 return m 934 } 935 936 //Return specifies results of invocation of Node.Leaving 937 func (m *mNodeMockLeaving) Return(r bool) *NodeMock { 938 m.mock.LeavingFunc = nil 939 m.expectationSeries = nil 940 941 if m.mainExpectation == nil { 942 m.mainExpectation = &NodeMockLeavingExpectation{} 943 } 944 m.mainExpectation.result = &NodeMockLeavingResult{r} 945 return m.mock 946 } 947 948 //ExpectOnce specifies that invocation of Node.Leaving is expected once 949 func (m *mNodeMockLeaving) ExpectOnce() *NodeMockLeavingExpectation { 950 m.mock.LeavingFunc = nil 951 m.mainExpectation = nil 952 953 expectation := &NodeMockLeavingExpectation{} 954 955 m.expectationSeries = append(m.expectationSeries, expectation) 956 return expectation 957 } 958 959 func (e *NodeMockLeavingExpectation) Return(r bool) { 960 e.result = &NodeMockLeavingResult{r} 961 } 962 963 //Set uses given function f as a mock of Node.Leaving method 964 func (m *mNodeMockLeaving) Set(f func() (r bool)) *NodeMock { 965 m.mainExpectation = nil 966 m.expectationSeries = nil 967 968 m.mock.LeavingFunc = f 969 return m.mock 970 } 971 972 //Leaving implements github.com/insolar/insolar/core.Node interface 973 func (m *NodeMock) Leaving() (r bool) { 974 counter := atomic.AddUint64(&m.LeavingPreCounter, 1) 975 defer atomic.AddUint64(&m.LeavingCounter, 1) 976 977 if len(m.LeavingMock.expectationSeries) > 0 { 978 if counter > uint64(len(m.LeavingMock.expectationSeries)) { 979 m.t.Fatalf("Unexpected call to NodeMock.Leaving.") 980 return 981 } 982 983 result := m.LeavingMock.expectationSeries[counter-1].result 984 if result == nil { 985 m.t.Fatal("No results are set for the NodeMock.Leaving") 986 return 987 } 988 989 r = result.r 990 991 return 992 } 993 994 if m.LeavingMock.mainExpectation != nil { 995 996 result := m.LeavingMock.mainExpectation.result 997 if result == nil { 998 m.t.Fatal("No results are set for the NodeMock.Leaving") 999 } 1000 1001 r = result.r 1002 1003 return 1004 } 1005 1006 if m.LeavingFunc == nil { 1007 m.t.Fatalf("Unexpected call to NodeMock.Leaving.") 1008 return 1009 } 1010 1011 return m.LeavingFunc() 1012 } 1013 1014 //LeavingMinimockCounter returns a count of NodeMock.LeavingFunc invocations 1015 func (m *NodeMock) LeavingMinimockCounter() uint64 { 1016 return atomic.LoadUint64(&m.LeavingCounter) 1017 } 1018 1019 //LeavingMinimockPreCounter returns the value of NodeMock.Leaving invocations 1020 func (m *NodeMock) LeavingMinimockPreCounter() uint64 { 1021 return atomic.LoadUint64(&m.LeavingPreCounter) 1022 } 1023 1024 //LeavingFinished returns true if mock invocations count is ok 1025 func (m *NodeMock) LeavingFinished() bool { 1026 // if expectation series were set then invocations count should be equal to expectations count 1027 if len(m.LeavingMock.expectationSeries) > 0 { 1028 return atomic.LoadUint64(&m.LeavingCounter) == uint64(len(m.LeavingMock.expectationSeries)) 1029 } 1030 1031 // if main expectation was set then invocations count should be greater than zero 1032 if m.LeavingMock.mainExpectation != nil { 1033 return atomic.LoadUint64(&m.LeavingCounter) > 0 1034 } 1035 1036 // if func was set then invocations count should be greater than zero 1037 if m.LeavingFunc != nil { 1038 return atomic.LoadUint64(&m.LeavingCounter) > 0 1039 } 1040 1041 return true 1042 } 1043 1044 type mNodeMockLeavingETA struct { 1045 mock *NodeMock 1046 mainExpectation *NodeMockLeavingETAExpectation 1047 expectationSeries []*NodeMockLeavingETAExpectation 1048 } 1049 1050 type NodeMockLeavingETAExpectation struct { 1051 result *NodeMockLeavingETAResult 1052 } 1053 1054 type NodeMockLeavingETAResult struct { 1055 r core.PulseNumber 1056 } 1057 1058 //Expect specifies that invocation of Node.LeavingETA is expected from 1 to Infinity times 1059 func (m *mNodeMockLeavingETA) Expect() *mNodeMockLeavingETA { 1060 m.mock.LeavingETAFunc = nil 1061 m.expectationSeries = nil 1062 1063 if m.mainExpectation == nil { 1064 m.mainExpectation = &NodeMockLeavingETAExpectation{} 1065 } 1066 1067 return m 1068 } 1069 1070 //Return specifies results of invocation of Node.LeavingETA 1071 func (m *mNodeMockLeavingETA) Return(r core.PulseNumber) *NodeMock { 1072 m.mock.LeavingETAFunc = nil 1073 m.expectationSeries = nil 1074 1075 if m.mainExpectation == nil { 1076 m.mainExpectation = &NodeMockLeavingETAExpectation{} 1077 } 1078 m.mainExpectation.result = &NodeMockLeavingETAResult{r} 1079 return m.mock 1080 } 1081 1082 //ExpectOnce specifies that invocation of Node.LeavingETA is expected once 1083 func (m *mNodeMockLeavingETA) ExpectOnce() *NodeMockLeavingETAExpectation { 1084 m.mock.LeavingETAFunc = nil 1085 m.mainExpectation = nil 1086 1087 expectation := &NodeMockLeavingETAExpectation{} 1088 1089 m.expectationSeries = append(m.expectationSeries, expectation) 1090 return expectation 1091 } 1092 1093 func (e *NodeMockLeavingETAExpectation) Return(r core.PulseNumber) { 1094 e.result = &NodeMockLeavingETAResult{r} 1095 } 1096 1097 //Set uses given function f as a mock of Node.LeavingETA method 1098 func (m *mNodeMockLeavingETA) Set(f func() (r core.PulseNumber)) *NodeMock { 1099 m.mainExpectation = nil 1100 m.expectationSeries = nil 1101 1102 m.mock.LeavingETAFunc = f 1103 return m.mock 1104 } 1105 1106 //LeavingETA implements github.com/insolar/insolar/core.Node interface 1107 func (m *NodeMock) LeavingETA() (r core.PulseNumber) { 1108 counter := atomic.AddUint64(&m.LeavingETAPreCounter, 1) 1109 defer atomic.AddUint64(&m.LeavingETACounter, 1) 1110 1111 if len(m.LeavingETAMock.expectationSeries) > 0 { 1112 if counter > uint64(len(m.LeavingETAMock.expectationSeries)) { 1113 m.t.Fatalf("Unexpected call to NodeMock.LeavingETA.") 1114 return 1115 } 1116 1117 result := m.LeavingETAMock.expectationSeries[counter-1].result 1118 if result == nil { 1119 m.t.Fatal("No results are set for the NodeMock.LeavingETA") 1120 return 1121 } 1122 1123 r = result.r 1124 1125 return 1126 } 1127 1128 if m.LeavingETAMock.mainExpectation != nil { 1129 1130 result := m.LeavingETAMock.mainExpectation.result 1131 if result == nil { 1132 m.t.Fatal("No results are set for the NodeMock.LeavingETA") 1133 } 1134 1135 r = result.r 1136 1137 return 1138 } 1139 1140 if m.LeavingETAFunc == nil { 1141 m.t.Fatalf("Unexpected call to NodeMock.LeavingETA.") 1142 return 1143 } 1144 1145 return m.LeavingETAFunc() 1146 } 1147 1148 //LeavingETAMinimockCounter returns a count of NodeMock.LeavingETAFunc invocations 1149 func (m *NodeMock) LeavingETAMinimockCounter() uint64 { 1150 return atomic.LoadUint64(&m.LeavingETACounter) 1151 } 1152 1153 //LeavingETAMinimockPreCounter returns the value of NodeMock.LeavingETA invocations 1154 func (m *NodeMock) LeavingETAMinimockPreCounter() uint64 { 1155 return atomic.LoadUint64(&m.LeavingETAPreCounter) 1156 } 1157 1158 //LeavingETAFinished returns true if mock invocations count is ok 1159 func (m *NodeMock) LeavingETAFinished() bool { 1160 // if expectation series were set then invocations count should be equal to expectations count 1161 if len(m.LeavingETAMock.expectationSeries) > 0 { 1162 return atomic.LoadUint64(&m.LeavingETACounter) == uint64(len(m.LeavingETAMock.expectationSeries)) 1163 } 1164 1165 // if main expectation was set then invocations count should be greater than zero 1166 if m.LeavingETAMock.mainExpectation != nil { 1167 return atomic.LoadUint64(&m.LeavingETACounter) > 0 1168 } 1169 1170 // if func was set then invocations count should be greater than zero 1171 if m.LeavingETAFunc != nil { 1172 return atomic.LoadUint64(&m.LeavingETACounter) > 0 1173 } 1174 1175 return true 1176 } 1177 1178 type mNodeMockPublicKey struct { 1179 mock *NodeMock 1180 mainExpectation *NodeMockPublicKeyExpectation 1181 expectationSeries []*NodeMockPublicKeyExpectation 1182 } 1183 1184 type NodeMockPublicKeyExpectation struct { 1185 result *NodeMockPublicKeyResult 1186 } 1187 1188 type NodeMockPublicKeyResult struct { 1189 r crypto.PublicKey 1190 } 1191 1192 //Expect specifies that invocation of Node.PublicKey is expected from 1 to Infinity times 1193 func (m *mNodeMockPublicKey) Expect() *mNodeMockPublicKey { 1194 m.mock.PublicKeyFunc = nil 1195 m.expectationSeries = nil 1196 1197 if m.mainExpectation == nil { 1198 m.mainExpectation = &NodeMockPublicKeyExpectation{} 1199 } 1200 1201 return m 1202 } 1203 1204 //Return specifies results of invocation of Node.PublicKey 1205 func (m *mNodeMockPublicKey) Return(r crypto.PublicKey) *NodeMock { 1206 m.mock.PublicKeyFunc = nil 1207 m.expectationSeries = nil 1208 1209 if m.mainExpectation == nil { 1210 m.mainExpectation = &NodeMockPublicKeyExpectation{} 1211 } 1212 m.mainExpectation.result = &NodeMockPublicKeyResult{r} 1213 return m.mock 1214 } 1215 1216 //ExpectOnce specifies that invocation of Node.PublicKey is expected once 1217 func (m *mNodeMockPublicKey) ExpectOnce() *NodeMockPublicKeyExpectation { 1218 m.mock.PublicKeyFunc = nil 1219 m.mainExpectation = nil 1220 1221 expectation := &NodeMockPublicKeyExpectation{} 1222 1223 m.expectationSeries = append(m.expectationSeries, expectation) 1224 return expectation 1225 } 1226 1227 func (e *NodeMockPublicKeyExpectation) Return(r crypto.PublicKey) { 1228 e.result = &NodeMockPublicKeyResult{r} 1229 } 1230 1231 //Set uses given function f as a mock of Node.PublicKey method 1232 func (m *mNodeMockPublicKey) Set(f func() (r crypto.PublicKey)) *NodeMock { 1233 m.mainExpectation = nil 1234 m.expectationSeries = nil 1235 1236 m.mock.PublicKeyFunc = f 1237 return m.mock 1238 } 1239 1240 //PublicKey implements github.com/insolar/insolar/core.Node interface 1241 func (m *NodeMock) PublicKey() (r crypto.PublicKey) { 1242 counter := atomic.AddUint64(&m.PublicKeyPreCounter, 1) 1243 defer atomic.AddUint64(&m.PublicKeyCounter, 1) 1244 1245 if len(m.PublicKeyMock.expectationSeries) > 0 { 1246 if counter > uint64(len(m.PublicKeyMock.expectationSeries)) { 1247 m.t.Fatalf("Unexpected call to NodeMock.PublicKey.") 1248 return 1249 } 1250 1251 result := m.PublicKeyMock.expectationSeries[counter-1].result 1252 if result == nil { 1253 m.t.Fatal("No results are set for the NodeMock.PublicKey") 1254 return 1255 } 1256 1257 r = result.r 1258 1259 return 1260 } 1261 1262 if m.PublicKeyMock.mainExpectation != nil { 1263 1264 result := m.PublicKeyMock.mainExpectation.result 1265 if result == nil { 1266 m.t.Fatal("No results are set for the NodeMock.PublicKey") 1267 } 1268 1269 r = result.r 1270 1271 return 1272 } 1273 1274 if m.PublicKeyFunc == nil { 1275 m.t.Fatalf("Unexpected call to NodeMock.PublicKey.") 1276 return 1277 } 1278 1279 return m.PublicKeyFunc() 1280 } 1281 1282 //PublicKeyMinimockCounter returns a count of NodeMock.PublicKeyFunc invocations 1283 func (m *NodeMock) PublicKeyMinimockCounter() uint64 { 1284 return atomic.LoadUint64(&m.PublicKeyCounter) 1285 } 1286 1287 //PublicKeyMinimockPreCounter returns the value of NodeMock.PublicKey invocations 1288 func (m *NodeMock) PublicKeyMinimockPreCounter() uint64 { 1289 return atomic.LoadUint64(&m.PublicKeyPreCounter) 1290 } 1291 1292 //PublicKeyFinished returns true if mock invocations count is ok 1293 func (m *NodeMock) PublicKeyFinished() bool { 1294 // if expectation series were set then invocations count should be equal to expectations count 1295 if len(m.PublicKeyMock.expectationSeries) > 0 { 1296 return atomic.LoadUint64(&m.PublicKeyCounter) == uint64(len(m.PublicKeyMock.expectationSeries)) 1297 } 1298 1299 // if main expectation was set then invocations count should be greater than zero 1300 if m.PublicKeyMock.mainExpectation != nil { 1301 return atomic.LoadUint64(&m.PublicKeyCounter) > 0 1302 } 1303 1304 // if func was set then invocations count should be greater than zero 1305 if m.PublicKeyFunc != nil { 1306 return atomic.LoadUint64(&m.PublicKeyCounter) > 0 1307 } 1308 1309 return true 1310 } 1311 1312 type mNodeMockRole struct { 1313 mock *NodeMock 1314 mainExpectation *NodeMockRoleExpectation 1315 expectationSeries []*NodeMockRoleExpectation 1316 } 1317 1318 type NodeMockRoleExpectation struct { 1319 result *NodeMockRoleResult 1320 } 1321 1322 type NodeMockRoleResult struct { 1323 r core.StaticRole 1324 } 1325 1326 //Expect specifies that invocation of Node.Role is expected from 1 to Infinity times 1327 func (m *mNodeMockRole) Expect() *mNodeMockRole { 1328 m.mock.RoleFunc = nil 1329 m.expectationSeries = nil 1330 1331 if m.mainExpectation == nil { 1332 m.mainExpectation = &NodeMockRoleExpectation{} 1333 } 1334 1335 return m 1336 } 1337 1338 //Return specifies results of invocation of Node.Role 1339 func (m *mNodeMockRole) Return(r core.StaticRole) *NodeMock { 1340 m.mock.RoleFunc = nil 1341 m.expectationSeries = nil 1342 1343 if m.mainExpectation == nil { 1344 m.mainExpectation = &NodeMockRoleExpectation{} 1345 } 1346 m.mainExpectation.result = &NodeMockRoleResult{r} 1347 return m.mock 1348 } 1349 1350 //ExpectOnce specifies that invocation of Node.Role is expected once 1351 func (m *mNodeMockRole) ExpectOnce() *NodeMockRoleExpectation { 1352 m.mock.RoleFunc = nil 1353 m.mainExpectation = nil 1354 1355 expectation := &NodeMockRoleExpectation{} 1356 1357 m.expectationSeries = append(m.expectationSeries, expectation) 1358 return expectation 1359 } 1360 1361 func (e *NodeMockRoleExpectation) Return(r core.StaticRole) { 1362 e.result = &NodeMockRoleResult{r} 1363 } 1364 1365 //Set uses given function f as a mock of Node.Role method 1366 func (m *mNodeMockRole) Set(f func() (r core.StaticRole)) *NodeMock { 1367 m.mainExpectation = nil 1368 m.expectationSeries = nil 1369 1370 m.mock.RoleFunc = f 1371 return m.mock 1372 } 1373 1374 //Role implements github.com/insolar/insolar/core.Node interface 1375 func (m *NodeMock) Role() (r core.StaticRole) { 1376 counter := atomic.AddUint64(&m.RolePreCounter, 1) 1377 defer atomic.AddUint64(&m.RoleCounter, 1) 1378 1379 if len(m.RoleMock.expectationSeries) > 0 { 1380 if counter > uint64(len(m.RoleMock.expectationSeries)) { 1381 m.t.Fatalf("Unexpected call to NodeMock.Role.") 1382 return 1383 } 1384 1385 result := m.RoleMock.expectationSeries[counter-1].result 1386 if result == nil { 1387 m.t.Fatal("No results are set for the NodeMock.Role") 1388 return 1389 } 1390 1391 r = result.r 1392 1393 return 1394 } 1395 1396 if m.RoleMock.mainExpectation != nil { 1397 1398 result := m.RoleMock.mainExpectation.result 1399 if result == nil { 1400 m.t.Fatal("No results are set for the NodeMock.Role") 1401 } 1402 1403 r = result.r 1404 1405 return 1406 } 1407 1408 if m.RoleFunc == nil { 1409 m.t.Fatalf("Unexpected call to NodeMock.Role.") 1410 return 1411 } 1412 1413 return m.RoleFunc() 1414 } 1415 1416 //RoleMinimockCounter returns a count of NodeMock.RoleFunc invocations 1417 func (m *NodeMock) RoleMinimockCounter() uint64 { 1418 return atomic.LoadUint64(&m.RoleCounter) 1419 } 1420 1421 //RoleMinimockPreCounter returns the value of NodeMock.Role invocations 1422 func (m *NodeMock) RoleMinimockPreCounter() uint64 { 1423 return atomic.LoadUint64(&m.RolePreCounter) 1424 } 1425 1426 //RoleFinished returns true if mock invocations count is ok 1427 func (m *NodeMock) RoleFinished() bool { 1428 // if expectation series were set then invocations count should be equal to expectations count 1429 if len(m.RoleMock.expectationSeries) > 0 { 1430 return atomic.LoadUint64(&m.RoleCounter) == uint64(len(m.RoleMock.expectationSeries)) 1431 } 1432 1433 // if main expectation was set then invocations count should be greater than zero 1434 if m.RoleMock.mainExpectation != nil { 1435 return atomic.LoadUint64(&m.RoleCounter) > 0 1436 } 1437 1438 // if func was set then invocations count should be greater than zero 1439 if m.RoleFunc != nil { 1440 return atomic.LoadUint64(&m.RoleCounter) > 0 1441 } 1442 1443 return true 1444 } 1445 1446 type mNodeMockShortID struct { 1447 mock *NodeMock 1448 mainExpectation *NodeMockShortIDExpectation 1449 expectationSeries []*NodeMockShortIDExpectation 1450 } 1451 1452 type NodeMockShortIDExpectation struct { 1453 result *NodeMockShortIDResult 1454 } 1455 1456 type NodeMockShortIDResult struct { 1457 r core.ShortNodeID 1458 } 1459 1460 //Expect specifies that invocation of Node.ShortID is expected from 1 to Infinity times 1461 func (m *mNodeMockShortID) Expect() *mNodeMockShortID { 1462 m.mock.ShortIDFunc = nil 1463 m.expectationSeries = nil 1464 1465 if m.mainExpectation == nil { 1466 m.mainExpectation = &NodeMockShortIDExpectation{} 1467 } 1468 1469 return m 1470 } 1471 1472 //Return specifies results of invocation of Node.ShortID 1473 func (m *mNodeMockShortID) Return(r core.ShortNodeID) *NodeMock { 1474 m.mock.ShortIDFunc = nil 1475 m.expectationSeries = nil 1476 1477 if m.mainExpectation == nil { 1478 m.mainExpectation = &NodeMockShortIDExpectation{} 1479 } 1480 m.mainExpectation.result = &NodeMockShortIDResult{r} 1481 return m.mock 1482 } 1483 1484 //ExpectOnce specifies that invocation of Node.ShortID is expected once 1485 func (m *mNodeMockShortID) ExpectOnce() *NodeMockShortIDExpectation { 1486 m.mock.ShortIDFunc = nil 1487 m.mainExpectation = nil 1488 1489 expectation := &NodeMockShortIDExpectation{} 1490 1491 m.expectationSeries = append(m.expectationSeries, expectation) 1492 return expectation 1493 } 1494 1495 func (e *NodeMockShortIDExpectation) Return(r core.ShortNodeID) { 1496 e.result = &NodeMockShortIDResult{r} 1497 } 1498 1499 //Set uses given function f as a mock of Node.ShortID method 1500 func (m *mNodeMockShortID) Set(f func() (r core.ShortNodeID)) *NodeMock { 1501 m.mainExpectation = nil 1502 m.expectationSeries = nil 1503 1504 m.mock.ShortIDFunc = f 1505 return m.mock 1506 } 1507 1508 //ShortID implements github.com/insolar/insolar/core.Node interface 1509 func (m *NodeMock) ShortID() (r core.ShortNodeID) { 1510 counter := atomic.AddUint64(&m.ShortIDPreCounter, 1) 1511 defer atomic.AddUint64(&m.ShortIDCounter, 1) 1512 1513 if len(m.ShortIDMock.expectationSeries) > 0 { 1514 if counter > uint64(len(m.ShortIDMock.expectationSeries)) { 1515 m.t.Fatalf("Unexpected call to NodeMock.ShortID.") 1516 return 1517 } 1518 1519 result := m.ShortIDMock.expectationSeries[counter-1].result 1520 if result == nil { 1521 m.t.Fatal("No results are set for the NodeMock.ShortID") 1522 return 1523 } 1524 1525 r = result.r 1526 1527 return 1528 } 1529 1530 if m.ShortIDMock.mainExpectation != nil { 1531 1532 result := m.ShortIDMock.mainExpectation.result 1533 if result == nil { 1534 m.t.Fatal("No results are set for the NodeMock.ShortID") 1535 } 1536 1537 r = result.r 1538 1539 return 1540 } 1541 1542 if m.ShortIDFunc == nil { 1543 m.t.Fatalf("Unexpected call to NodeMock.ShortID.") 1544 return 1545 } 1546 1547 return m.ShortIDFunc() 1548 } 1549 1550 //ShortIDMinimockCounter returns a count of NodeMock.ShortIDFunc invocations 1551 func (m *NodeMock) ShortIDMinimockCounter() uint64 { 1552 return atomic.LoadUint64(&m.ShortIDCounter) 1553 } 1554 1555 //ShortIDMinimockPreCounter returns the value of NodeMock.ShortID invocations 1556 func (m *NodeMock) ShortIDMinimockPreCounter() uint64 { 1557 return atomic.LoadUint64(&m.ShortIDPreCounter) 1558 } 1559 1560 //ShortIDFinished returns true if mock invocations count is ok 1561 func (m *NodeMock) ShortIDFinished() bool { 1562 // if expectation series were set then invocations count should be equal to expectations count 1563 if len(m.ShortIDMock.expectationSeries) > 0 { 1564 return atomic.LoadUint64(&m.ShortIDCounter) == uint64(len(m.ShortIDMock.expectationSeries)) 1565 } 1566 1567 // if main expectation was set then invocations count should be greater than zero 1568 if m.ShortIDMock.mainExpectation != nil { 1569 return atomic.LoadUint64(&m.ShortIDCounter) > 0 1570 } 1571 1572 // if func was set then invocations count should be greater than zero 1573 if m.ShortIDFunc != nil { 1574 return atomic.LoadUint64(&m.ShortIDCounter) > 0 1575 } 1576 1577 return true 1578 } 1579 1580 type mNodeMockVersion struct { 1581 mock *NodeMock 1582 mainExpectation *NodeMockVersionExpectation 1583 expectationSeries []*NodeMockVersionExpectation 1584 } 1585 1586 type NodeMockVersionExpectation struct { 1587 result *NodeMockVersionResult 1588 } 1589 1590 type NodeMockVersionResult struct { 1591 r string 1592 } 1593 1594 //Expect specifies that invocation of Node.Version is expected from 1 to Infinity times 1595 func (m *mNodeMockVersion) Expect() *mNodeMockVersion { 1596 m.mock.VersionFunc = nil 1597 m.expectationSeries = nil 1598 1599 if m.mainExpectation == nil { 1600 m.mainExpectation = &NodeMockVersionExpectation{} 1601 } 1602 1603 return m 1604 } 1605 1606 //Return specifies results of invocation of Node.Version 1607 func (m *mNodeMockVersion) Return(r string) *NodeMock { 1608 m.mock.VersionFunc = nil 1609 m.expectationSeries = nil 1610 1611 if m.mainExpectation == nil { 1612 m.mainExpectation = &NodeMockVersionExpectation{} 1613 } 1614 m.mainExpectation.result = &NodeMockVersionResult{r} 1615 return m.mock 1616 } 1617 1618 //ExpectOnce specifies that invocation of Node.Version is expected once 1619 func (m *mNodeMockVersion) ExpectOnce() *NodeMockVersionExpectation { 1620 m.mock.VersionFunc = nil 1621 m.mainExpectation = nil 1622 1623 expectation := &NodeMockVersionExpectation{} 1624 1625 m.expectationSeries = append(m.expectationSeries, expectation) 1626 return expectation 1627 } 1628 1629 func (e *NodeMockVersionExpectation) Return(r string) { 1630 e.result = &NodeMockVersionResult{r} 1631 } 1632 1633 //Set uses given function f as a mock of Node.Version method 1634 func (m *mNodeMockVersion) Set(f func() (r string)) *NodeMock { 1635 m.mainExpectation = nil 1636 m.expectationSeries = nil 1637 1638 m.mock.VersionFunc = f 1639 return m.mock 1640 } 1641 1642 //Version implements github.com/insolar/insolar/core.Node interface 1643 func (m *NodeMock) Version() (r string) { 1644 counter := atomic.AddUint64(&m.VersionPreCounter, 1) 1645 defer atomic.AddUint64(&m.VersionCounter, 1) 1646 1647 if len(m.VersionMock.expectationSeries) > 0 { 1648 if counter > uint64(len(m.VersionMock.expectationSeries)) { 1649 m.t.Fatalf("Unexpected call to NodeMock.Version.") 1650 return 1651 } 1652 1653 result := m.VersionMock.expectationSeries[counter-1].result 1654 if result == nil { 1655 m.t.Fatal("No results are set for the NodeMock.Version") 1656 return 1657 } 1658 1659 r = result.r 1660 1661 return 1662 } 1663 1664 if m.VersionMock.mainExpectation != nil { 1665 1666 result := m.VersionMock.mainExpectation.result 1667 if result == nil { 1668 m.t.Fatal("No results are set for the NodeMock.Version") 1669 } 1670 1671 r = result.r 1672 1673 return 1674 } 1675 1676 if m.VersionFunc == nil { 1677 m.t.Fatalf("Unexpected call to NodeMock.Version.") 1678 return 1679 } 1680 1681 return m.VersionFunc() 1682 } 1683 1684 //VersionMinimockCounter returns a count of NodeMock.VersionFunc invocations 1685 func (m *NodeMock) VersionMinimockCounter() uint64 { 1686 return atomic.LoadUint64(&m.VersionCounter) 1687 } 1688 1689 //VersionMinimockPreCounter returns the value of NodeMock.Version invocations 1690 func (m *NodeMock) VersionMinimockPreCounter() uint64 { 1691 return atomic.LoadUint64(&m.VersionPreCounter) 1692 } 1693 1694 //VersionFinished returns true if mock invocations count is ok 1695 func (m *NodeMock) VersionFinished() bool { 1696 // if expectation series were set then invocations count should be equal to expectations count 1697 if len(m.VersionMock.expectationSeries) > 0 { 1698 return atomic.LoadUint64(&m.VersionCounter) == uint64(len(m.VersionMock.expectationSeries)) 1699 } 1700 1701 // if main expectation was set then invocations count should be greater than zero 1702 if m.VersionMock.mainExpectation != nil { 1703 return atomic.LoadUint64(&m.VersionCounter) > 0 1704 } 1705 1706 // if func was set then invocations count should be greater than zero 1707 if m.VersionFunc != nil { 1708 return atomic.LoadUint64(&m.VersionCounter) > 0 1709 } 1710 1711 return true 1712 } 1713 1714 //ValidateCallCounters checks that all mocked methods of the interface have been called at least once 1715 //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller 1716 func (m *NodeMock) ValidateCallCounters() { 1717 1718 if !m.AddressFinished() { 1719 m.t.Fatal("Expected call to NodeMock.Address") 1720 } 1721 1722 if !m.ConsensusAddressFinished() { 1723 m.t.Fatal("Expected call to NodeMock.ConsensusAddress") 1724 } 1725 1726 if !m.GetGlobuleIDFinished() { 1727 m.t.Fatal("Expected call to NodeMock.GetGlobuleID") 1728 } 1729 1730 if !m.GetStateFinished() { 1731 m.t.Fatal("Expected call to NodeMock.GetState") 1732 } 1733 1734 if !m.IDFinished() { 1735 m.t.Fatal("Expected call to NodeMock.ID") 1736 } 1737 1738 if !m.IsWorkingFinished() { 1739 m.t.Fatal("Expected call to NodeMock.IsWorking") 1740 } 1741 1742 if !m.LeavingFinished() { 1743 m.t.Fatal("Expected call to NodeMock.Leaving") 1744 } 1745 1746 if !m.LeavingETAFinished() { 1747 m.t.Fatal("Expected call to NodeMock.LeavingETA") 1748 } 1749 1750 if !m.PublicKeyFinished() { 1751 m.t.Fatal("Expected call to NodeMock.PublicKey") 1752 } 1753 1754 if !m.RoleFinished() { 1755 m.t.Fatal("Expected call to NodeMock.Role") 1756 } 1757 1758 if !m.ShortIDFinished() { 1759 m.t.Fatal("Expected call to NodeMock.ShortID") 1760 } 1761 1762 if !m.VersionFinished() { 1763 m.t.Fatal("Expected call to NodeMock.Version") 1764 } 1765 1766 } 1767 1768 //CheckMocksCalled checks that all mocked methods of the interface have been called at least once 1769 //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller 1770 func (m *NodeMock) CheckMocksCalled() { 1771 m.Finish() 1772 } 1773 1774 //Finish checks that all mocked methods of the interface have been called at least once 1775 //Deprecated: please use MinimockFinish or use Finish method of minimock.Controller 1776 func (m *NodeMock) Finish() { 1777 m.MinimockFinish() 1778 } 1779 1780 //MinimockFinish checks that all mocked methods of the interface have been called at least once 1781 func (m *NodeMock) MinimockFinish() { 1782 1783 if !m.AddressFinished() { 1784 m.t.Fatal("Expected call to NodeMock.Address") 1785 } 1786 1787 if !m.ConsensusAddressFinished() { 1788 m.t.Fatal("Expected call to NodeMock.ConsensusAddress") 1789 } 1790 1791 if !m.GetGlobuleIDFinished() { 1792 m.t.Fatal("Expected call to NodeMock.GetGlobuleID") 1793 } 1794 1795 if !m.GetStateFinished() { 1796 m.t.Fatal("Expected call to NodeMock.GetState") 1797 } 1798 1799 if !m.IDFinished() { 1800 m.t.Fatal("Expected call to NodeMock.ID") 1801 } 1802 1803 if !m.IsWorkingFinished() { 1804 m.t.Fatal("Expected call to NodeMock.IsWorking") 1805 } 1806 1807 if !m.LeavingFinished() { 1808 m.t.Fatal("Expected call to NodeMock.Leaving") 1809 } 1810 1811 if !m.LeavingETAFinished() { 1812 m.t.Fatal("Expected call to NodeMock.LeavingETA") 1813 } 1814 1815 if !m.PublicKeyFinished() { 1816 m.t.Fatal("Expected call to NodeMock.PublicKey") 1817 } 1818 1819 if !m.RoleFinished() { 1820 m.t.Fatal("Expected call to NodeMock.Role") 1821 } 1822 1823 if !m.ShortIDFinished() { 1824 m.t.Fatal("Expected call to NodeMock.ShortID") 1825 } 1826 1827 if !m.VersionFinished() { 1828 m.t.Fatal("Expected call to NodeMock.Version") 1829 } 1830 1831 } 1832 1833 //Wait waits for all mocked methods to be called at least once 1834 //Deprecated: please use MinimockWait or use Wait method of minimock.Controller 1835 func (m *NodeMock) Wait(timeout time.Duration) { 1836 m.MinimockWait(timeout) 1837 } 1838 1839 //MinimockWait waits for all mocked methods to be called at least once 1840 //this method is called by minimock.Controller 1841 func (m *NodeMock) MinimockWait(timeout time.Duration) { 1842 timeoutCh := time.After(timeout) 1843 for { 1844 ok := true 1845 ok = ok && m.AddressFinished() 1846 ok = ok && m.ConsensusAddressFinished() 1847 ok = ok && m.GetGlobuleIDFinished() 1848 ok = ok && m.GetStateFinished() 1849 ok = ok && m.IDFinished() 1850 ok = ok && m.IsWorkingFinished() 1851 ok = ok && m.LeavingFinished() 1852 ok = ok && m.LeavingETAFinished() 1853 ok = ok && m.PublicKeyFinished() 1854 ok = ok && m.RoleFinished() 1855 ok = ok && m.ShortIDFinished() 1856 ok = ok && m.VersionFinished() 1857 1858 if ok { 1859 return 1860 } 1861 1862 select { 1863 case <-timeoutCh: 1864 1865 if !m.AddressFinished() { 1866 m.t.Error("Expected call to NodeMock.Address") 1867 } 1868 1869 if !m.ConsensusAddressFinished() { 1870 m.t.Error("Expected call to NodeMock.ConsensusAddress") 1871 } 1872 1873 if !m.GetGlobuleIDFinished() { 1874 m.t.Error("Expected call to NodeMock.GetGlobuleID") 1875 } 1876 1877 if !m.GetStateFinished() { 1878 m.t.Error("Expected call to NodeMock.GetState") 1879 } 1880 1881 if !m.IDFinished() { 1882 m.t.Error("Expected call to NodeMock.ID") 1883 } 1884 1885 if !m.IsWorkingFinished() { 1886 m.t.Error("Expected call to NodeMock.IsWorking") 1887 } 1888 1889 if !m.LeavingFinished() { 1890 m.t.Error("Expected call to NodeMock.Leaving") 1891 } 1892 1893 if !m.LeavingETAFinished() { 1894 m.t.Error("Expected call to NodeMock.LeavingETA") 1895 } 1896 1897 if !m.PublicKeyFinished() { 1898 m.t.Error("Expected call to NodeMock.PublicKey") 1899 } 1900 1901 if !m.RoleFinished() { 1902 m.t.Error("Expected call to NodeMock.Role") 1903 } 1904 1905 if !m.ShortIDFinished() { 1906 m.t.Error("Expected call to NodeMock.ShortID") 1907 } 1908 1909 if !m.VersionFinished() { 1910 m.t.Error("Expected call to NodeMock.Version") 1911 } 1912 1913 m.t.Fatalf("Some mocks were not called on time: %s", timeout) 1914 return 1915 default: 1916 time.Sleep(time.Millisecond) 1917 } 1918 } 1919 } 1920 1921 //AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled, 1922 //it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled()) 1923 func (m *NodeMock) AllMocksCalled() bool { 1924 1925 if !m.AddressFinished() { 1926 return false 1927 } 1928 1929 if !m.ConsensusAddressFinished() { 1930 return false 1931 } 1932 1933 if !m.GetGlobuleIDFinished() { 1934 return false 1935 } 1936 1937 if !m.GetStateFinished() { 1938 return false 1939 } 1940 1941 if !m.IDFinished() { 1942 return false 1943 } 1944 1945 if !m.IsWorkingFinished() { 1946 return false 1947 } 1948 1949 if !m.LeavingFinished() { 1950 return false 1951 } 1952 1953 if !m.LeavingETAFinished() { 1954 return false 1955 } 1956 1957 if !m.PublicKeyFinished() { 1958 return false 1959 } 1960 1961 if !m.RoleFinished() { 1962 return false 1963 } 1964 1965 if !m.ShortIDFinished() { 1966 return false 1967 } 1968 1969 if !m.VersionFinished() { 1970 return false 1971 } 1972 1973 return true 1974 }