github.com/braveheart12/just@v0.8.7/testutils/pulse_distributor_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 "PulseDistributor" can be found in github.com/insolar/insolar/core
     7  */
     8  import (
     9  	context "context"
    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  //PulseDistributorMock implements github.com/insolar/insolar/core.PulseDistributor
    20  type PulseDistributorMock struct {
    21  	t minimock.Tester
    22  
    23  	DistributeFunc       func(p context.Context, p1 core.Pulse)
    24  	DistributeCounter    uint64
    25  	DistributePreCounter uint64
    26  	DistributeMock       mPulseDistributorMockDistribute
    27  }
    28  
    29  //NewPulseDistributorMock returns a mock for github.com/insolar/insolar/core.PulseDistributor
    30  func NewPulseDistributorMock(t minimock.Tester) *PulseDistributorMock {
    31  	m := &PulseDistributorMock{t: t}
    32  
    33  	if controller, ok := t.(minimock.MockController); ok {
    34  		controller.RegisterMocker(m)
    35  	}
    36  
    37  	m.DistributeMock = mPulseDistributorMockDistribute{mock: m}
    38  
    39  	return m
    40  }
    41  
    42  type mPulseDistributorMockDistribute struct {
    43  	mock              *PulseDistributorMock
    44  	mainExpectation   *PulseDistributorMockDistributeExpectation
    45  	expectationSeries []*PulseDistributorMockDistributeExpectation
    46  }
    47  
    48  type PulseDistributorMockDistributeExpectation struct {
    49  	input *PulseDistributorMockDistributeInput
    50  }
    51  
    52  type PulseDistributorMockDistributeInput struct {
    53  	p  context.Context
    54  	p1 core.Pulse
    55  }
    56  
    57  //Expect specifies that invocation of PulseDistributor.Distribute is expected from 1 to Infinity times
    58  func (m *mPulseDistributorMockDistribute) Expect(p context.Context, p1 core.Pulse) *mPulseDistributorMockDistribute {
    59  	m.mock.DistributeFunc = nil
    60  	m.expectationSeries = nil
    61  
    62  	if m.mainExpectation == nil {
    63  		m.mainExpectation = &PulseDistributorMockDistributeExpectation{}
    64  	}
    65  	m.mainExpectation.input = &PulseDistributorMockDistributeInput{p, p1}
    66  	return m
    67  }
    68  
    69  //Return specifies results of invocation of PulseDistributor.Distribute
    70  func (m *mPulseDistributorMockDistribute) Return() *PulseDistributorMock {
    71  	m.mock.DistributeFunc = nil
    72  	m.expectationSeries = nil
    73  
    74  	if m.mainExpectation == nil {
    75  		m.mainExpectation = &PulseDistributorMockDistributeExpectation{}
    76  	}
    77  
    78  	return m.mock
    79  }
    80  
    81  //ExpectOnce specifies that invocation of PulseDistributor.Distribute is expected once
    82  func (m *mPulseDistributorMockDistribute) ExpectOnce(p context.Context, p1 core.Pulse) *PulseDistributorMockDistributeExpectation {
    83  	m.mock.DistributeFunc = nil
    84  	m.mainExpectation = nil
    85  
    86  	expectation := &PulseDistributorMockDistributeExpectation{}
    87  	expectation.input = &PulseDistributorMockDistributeInput{p, p1}
    88  	m.expectationSeries = append(m.expectationSeries, expectation)
    89  	return expectation
    90  }
    91  
    92  //Set uses given function f as a mock of PulseDistributor.Distribute method
    93  func (m *mPulseDistributorMockDistribute) Set(f func(p context.Context, p1 core.Pulse)) *PulseDistributorMock {
    94  	m.mainExpectation = nil
    95  	m.expectationSeries = nil
    96  
    97  	m.mock.DistributeFunc = f
    98  	return m.mock
    99  }
   100  
   101  //Distribute implements github.com/insolar/insolar/core.PulseDistributor interface
   102  func (m *PulseDistributorMock) Distribute(p context.Context, p1 core.Pulse) {
   103  	counter := atomic.AddUint64(&m.DistributePreCounter, 1)
   104  	defer atomic.AddUint64(&m.DistributeCounter, 1)
   105  
   106  	if len(m.DistributeMock.expectationSeries) > 0 {
   107  		if counter > uint64(len(m.DistributeMock.expectationSeries)) {
   108  			m.t.Fatalf("Unexpected call to PulseDistributorMock.Distribute. %v %v", p, p1)
   109  			return
   110  		}
   111  
   112  		input := m.DistributeMock.expectationSeries[counter-1].input
   113  		testify_assert.Equal(m.t, *input, PulseDistributorMockDistributeInput{p, p1}, "PulseDistributor.Distribute got unexpected parameters")
   114  
   115  		return
   116  	}
   117  
   118  	if m.DistributeMock.mainExpectation != nil {
   119  
   120  		input := m.DistributeMock.mainExpectation.input
   121  		if input != nil {
   122  			testify_assert.Equal(m.t, *input, PulseDistributorMockDistributeInput{p, p1}, "PulseDistributor.Distribute got unexpected parameters")
   123  		}
   124  
   125  		return
   126  	}
   127  
   128  	if m.DistributeFunc == nil {
   129  		m.t.Fatalf("Unexpected call to PulseDistributorMock.Distribute. %v %v", p, p1)
   130  		return
   131  	}
   132  
   133  	m.DistributeFunc(p, p1)
   134  }
   135  
   136  //DistributeMinimockCounter returns a count of PulseDistributorMock.DistributeFunc invocations
   137  func (m *PulseDistributorMock) DistributeMinimockCounter() uint64 {
   138  	return atomic.LoadUint64(&m.DistributeCounter)
   139  }
   140  
   141  //DistributeMinimockPreCounter returns the value of PulseDistributorMock.Distribute invocations
   142  func (m *PulseDistributorMock) DistributeMinimockPreCounter() uint64 {
   143  	return atomic.LoadUint64(&m.DistributePreCounter)
   144  }
   145  
   146  //DistributeFinished returns true if mock invocations count is ok
   147  func (m *PulseDistributorMock) DistributeFinished() bool {
   148  	// if expectation series were set then invocations count should be equal to expectations count
   149  	if len(m.DistributeMock.expectationSeries) > 0 {
   150  		return atomic.LoadUint64(&m.DistributeCounter) == uint64(len(m.DistributeMock.expectationSeries))
   151  	}
   152  
   153  	// if main expectation was set then invocations count should be greater than zero
   154  	if m.DistributeMock.mainExpectation != nil {
   155  		return atomic.LoadUint64(&m.DistributeCounter) > 0
   156  	}
   157  
   158  	// if func was set then invocations count should be greater than zero
   159  	if m.DistributeFunc != nil {
   160  		return atomic.LoadUint64(&m.DistributeCounter) > 0
   161  	}
   162  
   163  	return true
   164  }
   165  
   166  //ValidateCallCounters checks that all mocked methods of the interface have been called at least once
   167  //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
   168  func (m *PulseDistributorMock) ValidateCallCounters() {
   169  
   170  	if !m.DistributeFinished() {
   171  		m.t.Fatal("Expected call to PulseDistributorMock.Distribute")
   172  	}
   173  
   174  }
   175  
   176  //CheckMocksCalled checks that all mocked methods of the interface have been called at least once
   177  //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
   178  func (m *PulseDistributorMock) CheckMocksCalled() {
   179  	m.Finish()
   180  }
   181  
   182  //Finish checks that all mocked methods of the interface have been called at least once
   183  //Deprecated: please use MinimockFinish or use Finish method of minimock.Controller
   184  func (m *PulseDistributorMock) Finish() {
   185  	m.MinimockFinish()
   186  }
   187  
   188  //MinimockFinish checks that all mocked methods of the interface have been called at least once
   189  func (m *PulseDistributorMock) MinimockFinish() {
   190  
   191  	if !m.DistributeFinished() {
   192  		m.t.Fatal("Expected call to PulseDistributorMock.Distribute")
   193  	}
   194  
   195  }
   196  
   197  //Wait waits for all mocked methods to be called at least once
   198  //Deprecated: please use MinimockWait or use Wait method of minimock.Controller
   199  func (m *PulseDistributorMock) Wait(timeout time.Duration) {
   200  	m.MinimockWait(timeout)
   201  }
   202  
   203  //MinimockWait waits for all mocked methods to be called at least once
   204  //this method is called by minimock.Controller
   205  func (m *PulseDistributorMock) MinimockWait(timeout time.Duration) {
   206  	timeoutCh := time.After(timeout)
   207  	for {
   208  		ok := true
   209  		ok = ok && m.DistributeFinished()
   210  
   211  		if ok {
   212  			return
   213  		}
   214  
   215  		select {
   216  		case <-timeoutCh:
   217  
   218  			if !m.DistributeFinished() {
   219  				m.t.Error("Expected call to PulseDistributorMock.Distribute")
   220  			}
   221  
   222  			m.t.Fatalf("Some mocks were not called on time: %s", timeout)
   223  			return
   224  		default:
   225  			time.Sleep(time.Millisecond)
   226  		}
   227  	}
   228  }
   229  
   230  //AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled,
   231  //it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled())
   232  func (m *PulseDistributorMock) AllMocksCalled() bool {
   233  
   234  	if !m.DistributeFinished() {
   235  		return false
   236  	}
   237  
   238  	return true
   239  }