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