github.com/braveheart12/just@v0.8.7/testutils/network/pulse_handler_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 "PulseHandler" can be found in github.com/insolar/insolar/network 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 //PulseHandlerMock implements github.com/insolar/insolar/network.PulseHandler 20 type PulseHandlerMock struct { 21 t minimock.Tester 22 23 HandlePulseFunc func(p context.Context, p1 core.Pulse) 24 HandlePulseCounter uint64 25 HandlePulsePreCounter uint64 26 HandlePulseMock mPulseHandlerMockHandlePulse 27 } 28 29 //NewPulseHandlerMock returns a mock for github.com/insolar/insolar/network.PulseHandler 30 func NewPulseHandlerMock(t minimock.Tester) *PulseHandlerMock { 31 m := &PulseHandlerMock{t: t} 32 33 if controller, ok := t.(minimock.MockController); ok { 34 controller.RegisterMocker(m) 35 } 36 37 m.HandlePulseMock = mPulseHandlerMockHandlePulse{mock: m} 38 39 return m 40 } 41 42 type mPulseHandlerMockHandlePulse struct { 43 mock *PulseHandlerMock 44 mainExpectation *PulseHandlerMockHandlePulseExpectation 45 expectationSeries []*PulseHandlerMockHandlePulseExpectation 46 } 47 48 type PulseHandlerMockHandlePulseExpectation struct { 49 input *PulseHandlerMockHandlePulseInput 50 } 51 52 type PulseHandlerMockHandlePulseInput struct { 53 p context.Context 54 p1 core.Pulse 55 } 56 57 //Expect specifies that invocation of PulseHandler.HandlePulse is expected from 1 to Infinity times 58 func (m *mPulseHandlerMockHandlePulse) Expect(p context.Context, p1 core.Pulse) *mPulseHandlerMockHandlePulse { 59 m.mock.HandlePulseFunc = nil 60 m.expectationSeries = nil 61 62 if m.mainExpectation == nil { 63 m.mainExpectation = &PulseHandlerMockHandlePulseExpectation{} 64 } 65 m.mainExpectation.input = &PulseHandlerMockHandlePulseInput{p, p1} 66 return m 67 } 68 69 //Return specifies results of invocation of PulseHandler.HandlePulse 70 func (m *mPulseHandlerMockHandlePulse) Return() *PulseHandlerMock { 71 m.mock.HandlePulseFunc = nil 72 m.expectationSeries = nil 73 74 if m.mainExpectation == nil { 75 m.mainExpectation = &PulseHandlerMockHandlePulseExpectation{} 76 } 77 78 return m.mock 79 } 80 81 //ExpectOnce specifies that invocation of PulseHandler.HandlePulse is expected once 82 func (m *mPulseHandlerMockHandlePulse) ExpectOnce(p context.Context, p1 core.Pulse) *PulseHandlerMockHandlePulseExpectation { 83 m.mock.HandlePulseFunc = nil 84 m.mainExpectation = nil 85 86 expectation := &PulseHandlerMockHandlePulseExpectation{} 87 expectation.input = &PulseHandlerMockHandlePulseInput{p, p1} 88 m.expectationSeries = append(m.expectationSeries, expectation) 89 return expectation 90 } 91 92 //Set uses given function f as a mock of PulseHandler.HandlePulse method 93 func (m *mPulseHandlerMockHandlePulse) Set(f func(p context.Context, p1 core.Pulse)) *PulseHandlerMock { 94 m.mainExpectation = nil 95 m.expectationSeries = nil 96 97 m.mock.HandlePulseFunc = f 98 return m.mock 99 } 100 101 //HandlePulse implements github.com/insolar/insolar/network.PulseHandler interface 102 func (m *PulseHandlerMock) HandlePulse(p context.Context, p1 core.Pulse) { 103 counter := atomic.AddUint64(&m.HandlePulsePreCounter, 1) 104 defer atomic.AddUint64(&m.HandlePulseCounter, 1) 105 106 if len(m.HandlePulseMock.expectationSeries) > 0 { 107 if counter > uint64(len(m.HandlePulseMock.expectationSeries)) { 108 m.t.Fatalf("Unexpected call to PulseHandlerMock.HandlePulse. %v %v", p, p1) 109 return 110 } 111 112 input := m.HandlePulseMock.expectationSeries[counter-1].input 113 testify_assert.Equal(m.t, *input, PulseHandlerMockHandlePulseInput{p, p1}, "PulseHandler.HandlePulse got unexpected parameters") 114 115 return 116 } 117 118 if m.HandlePulseMock.mainExpectation != nil { 119 120 input := m.HandlePulseMock.mainExpectation.input 121 if input != nil { 122 testify_assert.Equal(m.t, *input, PulseHandlerMockHandlePulseInput{p, p1}, "PulseHandler.HandlePulse got unexpected parameters") 123 } 124 125 return 126 } 127 128 if m.HandlePulseFunc == nil { 129 m.t.Fatalf("Unexpected call to PulseHandlerMock.HandlePulse. %v %v", p, p1) 130 return 131 } 132 133 m.HandlePulseFunc(p, p1) 134 } 135 136 //HandlePulseMinimockCounter returns a count of PulseHandlerMock.HandlePulseFunc invocations 137 func (m *PulseHandlerMock) HandlePulseMinimockCounter() uint64 { 138 return atomic.LoadUint64(&m.HandlePulseCounter) 139 } 140 141 //HandlePulseMinimockPreCounter returns the value of PulseHandlerMock.HandlePulse invocations 142 func (m *PulseHandlerMock) HandlePulseMinimockPreCounter() uint64 { 143 return atomic.LoadUint64(&m.HandlePulsePreCounter) 144 } 145 146 //HandlePulseFinished returns true if mock invocations count is ok 147 func (m *PulseHandlerMock) HandlePulseFinished() bool { 148 // if expectation series were set then invocations count should be equal to expectations count 149 if len(m.HandlePulseMock.expectationSeries) > 0 { 150 return atomic.LoadUint64(&m.HandlePulseCounter) == uint64(len(m.HandlePulseMock.expectationSeries)) 151 } 152 153 // if main expectation was set then invocations count should be greater than zero 154 if m.HandlePulseMock.mainExpectation != nil { 155 return atomic.LoadUint64(&m.HandlePulseCounter) > 0 156 } 157 158 // if func was set then invocations count should be greater than zero 159 if m.HandlePulseFunc != nil { 160 return atomic.LoadUint64(&m.HandlePulseCounter) > 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 *PulseHandlerMock) ValidateCallCounters() { 169 170 if !m.HandlePulseFinished() { 171 m.t.Fatal("Expected call to PulseHandlerMock.HandlePulse") 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 *PulseHandlerMock) 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 *PulseHandlerMock) 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 *PulseHandlerMock) MinimockFinish() { 190 191 if !m.HandlePulseFinished() { 192 m.t.Fatal("Expected call to PulseHandlerMock.HandlePulse") 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 *PulseHandlerMock) 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 *PulseHandlerMock) MinimockWait(timeout time.Duration) { 206 timeoutCh := time.After(timeout) 207 for { 208 ok := true 209 ok = ok && m.HandlePulseFinished() 210 211 if ok { 212 return 213 } 214 215 select { 216 case <-timeoutCh: 217 218 if !m.HandlePulseFinished() { 219 m.t.Error("Expected call to PulseHandlerMock.HandlePulse") 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 *PulseHandlerMock) AllMocksCalled() bool { 233 234 if !m.HandlePulseFinished() { 235 return false 236 } 237 238 return true 239 }