github.com/braveheart12/insolar-09-08-19@v0.8.7/testutils/network/switcher_work_around_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 "SwitcherWorkAround" can be found in github.com/insolar/insolar/core
     7  */
     8  import (
     9  	"sync/atomic"
    10  	"time"
    11  
    12  	"github.com/gojuno/minimock"
    13  	testify_assert "github.com/stretchr/testify/assert"
    14  )
    15  
    16  //SwitcherWorkAroundMock implements github.com/insolar/insolar/core.SwitcherWorkAround
    17  type SwitcherWorkAroundMock struct {
    18  	t minimock.Tester
    19  
    20  	IsBootstrappedFunc       func() (r bool)
    21  	IsBootstrappedCounter    uint64
    22  	IsBootstrappedPreCounter uint64
    23  	IsBootstrappedMock       mSwitcherWorkAroundMockIsBootstrapped
    24  
    25  	SetIsBootstrappedFunc       func(p bool)
    26  	SetIsBootstrappedCounter    uint64
    27  	SetIsBootstrappedPreCounter uint64
    28  	SetIsBootstrappedMock       mSwitcherWorkAroundMockSetIsBootstrapped
    29  }
    30  
    31  //NewSwitcherWorkAroundMock returns a mock for github.com/insolar/insolar/core.SwitcherWorkAround
    32  func NewSwitcherWorkAroundMock(t minimock.Tester) *SwitcherWorkAroundMock {
    33  	m := &SwitcherWorkAroundMock{t: t}
    34  
    35  	if controller, ok := t.(minimock.MockController); ok {
    36  		controller.RegisterMocker(m)
    37  	}
    38  
    39  	m.IsBootstrappedMock = mSwitcherWorkAroundMockIsBootstrapped{mock: m}
    40  	m.SetIsBootstrappedMock = mSwitcherWorkAroundMockSetIsBootstrapped{mock: m}
    41  
    42  	return m
    43  }
    44  
    45  type mSwitcherWorkAroundMockIsBootstrapped struct {
    46  	mock              *SwitcherWorkAroundMock
    47  	mainExpectation   *SwitcherWorkAroundMockIsBootstrappedExpectation
    48  	expectationSeries []*SwitcherWorkAroundMockIsBootstrappedExpectation
    49  }
    50  
    51  type SwitcherWorkAroundMockIsBootstrappedExpectation struct {
    52  	result *SwitcherWorkAroundMockIsBootstrappedResult
    53  }
    54  
    55  type SwitcherWorkAroundMockIsBootstrappedResult struct {
    56  	r bool
    57  }
    58  
    59  //Expect specifies that invocation of SwitcherWorkAround.IsBootstrapped is expected from 1 to Infinity times
    60  func (m *mSwitcherWorkAroundMockIsBootstrapped) Expect() *mSwitcherWorkAroundMockIsBootstrapped {
    61  	m.mock.IsBootstrappedFunc = nil
    62  	m.expectationSeries = nil
    63  
    64  	if m.mainExpectation == nil {
    65  		m.mainExpectation = &SwitcherWorkAroundMockIsBootstrappedExpectation{}
    66  	}
    67  
    68  	return m
    69  }
    70  
    71  //Return specifies results of invocation of SwitcherWorkAround.IsBootstrapped
    72  func (m *mSwitcherWorkAroundMockIsBootstrapped) Return(r bool) *SwitcherWorkAroundMock {
    73  	m.mock.IsBootstrappedFunc = nil
    74  	m.expectationSeries = nil
    75  
    76  	if m.mainExpectation == nil {
    77  		m.mainExpectation = &SwitcherWorkAroundMockIsBootstrappedExpectation{}
    78  	}
    79  	m.mainExpectation.result = &SwitcherWorkAroundMockIsBootstrappedResult{r}
    80  	return m.mock
    81  }
    82  
    83  //ExpectOnce specifies that invocation of SwitcherWorkAround.IsBootstrapped is expected once
    84  func (m *mSwitcherWorkAroundMockIsBootstrapped) ExpectOnce() *SwitcherWorkAroundMockIsBootstrappedExpectation {
    85  	m.mock.IsBootstrappedFunc = nil
    86  	m.mainExpectation = nil
    87  
    88  	expectation := &SwitcherWorkAroundMockIsBootstrappedExpectation{}
    89  
    90  	m.expectationSeries = append(m.expectationSeries, expectation)
    91  	return expectation
    92  }
    93  
    94  func (e *SwitcherWorkAroundMockIsBootstrappedExpectation) Return(r bool) {
    95  	e.result = &SwitcherWorkAroundMockIsBootstrappedResult{r}
    96  }
    97  
    98  //Set uses given function f as a mock of SwitcherWorkAround.IsBootstrapped method
    99  func (m *mSwitcherWorkAroundMockIsBootstrapped) Set(f func() (r bool)) *SwitcherWorkAroundMock {
   100  	m.mainExpectation = nil
   101  	m.expectationSeries = nil
   102  
   103  	m.mock.IsBootstrappedFunc = f
   104  	return m.mock
   105  }
   106  
   107  //IsBootstrapped implements github.com/insolar/insolar/core.SwitcherWorkAround interface
   108  func (m *SwitcherWorkAroundMock) IsBootstrapped() (r bool) {
   109  	counter := atomic.AddUint64(&m.IsBootstrappedPreCounter, 1)
   110  	defer atomic.AddUint64(&m.IsBootstrappedCounter, 1)
   111  
   112  	if len(m.IsBootstrappedMock.expectationSeries) > 0 {
   113  		if counter > uint64(len(m.IsBootstrappedMock.expectationSeries)) {
   114  			m.t.Fatalf("Unexpected call to SwitcherWorkAroundMock.IsBootstrapped.")
   115  			return
   116  		}
   117  
   118  		result := m.IsBootstrappedMock.expectationSeries[counter-1].result
   119  		if result == nil {
   120  			m.t.Fatal("No results are set for the SwitcherWorkAroundMock.IsBootstrapped")
   121  			return
   122  		}
   123  
   124  		r = result.r
   125  
   126  		return
   127  	}
   128  
   129  	if m.IsBootstrappedMock.mainExpectation != nil {
   130  
   131  		result := m.IsBootstrappedMock.mainExpectation.result
   132  		if result == nil {
   133  			m.t.Fatal("No results are set for the SwitcherWorkAroundMock.IsBootstrapped")
   134  		}
   135  
   136  		r = result.r
   137  
   138  		return
   139  	}
   140  
   141  	if m.IsBootstrappedFunc == nil {
   142  		m.t.Fatalf("Unexpected call to SwitcherWorkAroundMock.IsBootstrapped.")
   143  		return
   144  	}
   145  
   146  	return m.IsBootstrappedFunc()
   147  }
   148  
   149  //IsBootstrappedMinimockCounter returns a count of SwitcherWorkAroundMock.IsBootstrappedFunc invocations
   150  func (m *SwitcherWorkAroundMock) IsBootstrappedMinimockCounter() uint64 {
   151  	return atomic.LoadUint64(&m.IsBootstrappedCounter)
   152  }
   153  
   154  //IsBootstrappedMinimockPreCounter returns the value of SwitcherWorkAroundMock.IsBootstrapped invocations
   155  func (m *SwitcherWorkAroundMock) IsBootstrappedMinimockPreCounter() uint64 {
   156  	return atomic.LoadUint64(&m.IsBootstrappedPreCounter)
   157  }
   158  
   159  //IsBootstrappedFinished returns true if mock invocations count is ok
   160  func (m *SwitcherWorkAroundMock) IsBootstrappedFinished() bool {
   161  	// if expectation series were set then invocations count should be equal to expectations count
   162  	if len(m.IsBootstrappedMock.expectationSeries) > 0 {
   163  		return atomic.LoadUint64(&m.IsBootstrappedCounter) == uint64(len(m.IsBootstrappedMock.expectationSeries))
   164  	}
   165  
   166  	// if main expectation was set then invocations count should be greater than zero
   167  	if m.IsBootstrappedMock.mainExpectation != nil {
   168  		return atomic.LoadUint64(&m.IsBootstrappedCounter) > 0
   169  	}
   170  
   171  	// if func was set then invocations count should be greater than zero
   172  	if m.IsBootstrappedFunc != nil {
   173  		return atomic.LoadUint64(&m.IsBootstrappedCounter) > 0
   174  	}
   175  
   176  	return true
   177  }
   178  
   179  type mSwitcherWorkAroundMockSetIsBootstrapped struct {
   180  	mock              *SwitcherWorkAroundMock
   181  	mainExpectation   *SwitcherWorkAroundMockSetIsBootstrappedExpectation
   182  	expectationSeries []*SwitcherWorkAroundMockSetIsBootstrappedExpectation
   183  }
   184  
   185  type SwitcherWorkAroundMockSetIsBootstrappedExpectation struct {
   186  	input *SwitcherWorkAroundMockSetIsBootstrappedInput
   187  }
   188  
   189  type SwitcherWorkAroundMockSetIsBootstrappedInput struct {
   190  	p bool
   191  }
   192  
   193  //Expect specifies that invocation of SwitcherWorkAround.SetIsBootstrapped is expected from 1 to Infinity times
   194  func (m *mSwitcherWorkAroundMockSetIsBootstrapped) Expect(p bool) *mSwitcherWorkAroundMockSetIsBootstrapped {
   195  	m.mock.SetIsBootstrappedFunc = nil
   196  	m.expectationSeries = nil
   197  
   198  	if m.mainExpectation == nil {
   199  		m.mainExpectation = &SwitcherWorkAroundMockSetIsBootstrappedExpectation{}
   200  	}
   201  	m.mainExpectation.input = &SwitcherWorkAroundMockSetIsBootstrappedInput{p}
   202  	return m
   203  }
   204  
   205  //Return specifies results of invocation of SwitcherWorkAround.SetIsBootstrapped
   206  func (m *mSwitcherWorkAroundMockSetIsBootstrapped) Return() *SwitcherWorkAroundMock {
   207  	m.mock.SetIsBootstrappedFunc = nil
   208  	m.expectationSeries = nil
   209  
   210  	if m.mainExpectation == nil {
   211  		m.mainExpectation = &SwitcherWorkAroundMockSetIsBootstrappedExpectation{}
   212  	}
   213  
   214  	return m.mock
   215  }
   216  
   217  //ExpectOnce specifies that invocation of SwitcherWorkAround.SetIsBootstrapped is expected once
   218  func (m *mSwitcherWorkAroundMockSetIsBootstrapped) ExpectOnce(p bool) *SwitcherWorkAroundMockSetIsBootstrappedExpectation {
   219  	m.mock.SetIsBootstrappedFunc = nil
   220  	m.mainExpectation = nil
   221  
   222  	expectation := &SwitcherWorkAroundMockSetIsBootstrappedExpectation{}
   223  	expectation.input = &SwitcherWorkAroundMockSetIsBootstrappedInput{p}
   224  	m.expectationSeries = append(m.expectationSeries, expectation)
   225  	return expectation
   226  }
   227  
   228  //Set uses given function f as a mock of SwitcherWorkAround.SetIsBootstrapped method
   229  func (m *mSwitcherWorkAroundMockSetIsBootstrapped) Set(f func(p bool)) *SwitcherWorkAroundMock {
   230  	m.mainExpectation = nil
   231  	m.expectationSeries = nil
   232  
   233  	m.mock.SetIsBootstrappedFunc = f
   234  	return m.mock
   235  }
   236  
   237  //SetIsBootstrapped implements github.com/insolar/insolar/core.SwitcherWorkAround interface
   238  func (m *SwitcherWorkAroundMock) SetIsBootstrapped(p bool) {
   239  	counter := atomic.AddUint64(&m.SetIsBootstrappedPreCounter, 1)
   240  	defer atomic.AddUint64(&m.SetIsBootstrappedCounter, 1)
   241  
   242  	if len(m.SetIsBootstrappedMock.expectationSeries) > 0 {
   243  		if counter > uint64(len(m.SetIsBootstrappedMock.expectationSeries)) {
   244  			m.t.Fatalf("Unexpected call to SwitcherWorkAroundMock.SetIsBootstrapped. %v", p)
   245  			return
   246  		}
   247  
   248  		input := m.SetIsBootstrappedMock.expectationSeries[counter-1].input
   249  		testify_assert.Equal(m.t, *input, SwitcherWorkAroundMockSetIsBootstrappedInput{p}, "SwitcherWorkAround.SetIsBootstrapped got unexpected parameters")
   250  
   251  		return
   252  	}
   253  
   254  	if m.SetIsBootstrappedMock.mainExpectation != nil {
   255  
   256  		input := m.SetIsBootstrappedMock.mainExpectation.input
   257  		if input != nil {
   258  			testify_assert.Equal(m.t, *input, SwitcherWorkAroundMockSetIsBootstrappedInput{p}, "SwitcherWorkAround.SetIsBootstrapped got unexpected parameters")
   259  		}
   260  
   261  		return
   262  	}
   263  
   264  	if m.SetIsBootstrappedFunc == nil {
   265  		m.t.Fatalf("Unexpected call to SwitcherWorkAroundMock.SetIsBootstrapped. %v", p)
   266  		return
   267  	}
   268  
   269  	m.SetIsBootstrappedFunc(p)
   270  }
   271  
   272  //SetIsBootstrappedMinimockCounter returns a count of SwitcherWorkAroundMock.SetIsBootstrappedFunc invocations
   273  func (m *SwitcherWorkAroundMock) SetIsBootstrappedMinimockCounter() uint64 {
   274  	return atomic.LoadUint64(&m.SetIsBootstrappedCounter)
   275  }
   276  
   277  //SetIsBootstrappedMinimockPreCounter returns the value of SwitcherWorkAroundMock.SetIsBootstrapped invocations
   278  func (m *SwitcherWorkAroundMock) SetIsBootstrappedMinimockPreCounter() uint64 {
   279  	return atomic.LoadUint64(&m.SetIsBootstrappedPreCounter)
   280  }
   281  
   282  //SetIsBootstrappedFinished returns true if mock invocations count is ok
   283  func (m *SwitcherWorkAroundMock) SetIsBootstrappedFinished() bool {
   284  	// if expectation series were set then invocations count should be equal to expectations count
   285  	if len(m.SetIsBootstrappedMock.expectationSeries) > 0 {
   286  		return atomic.LoadUint64(&m.SetIsBootstrappedCounter) == uint64(len(m.SetIsBootstrappedMock.expectationSeries))
   287  	}
   288  
   289  	// if main expectation was set then invocations count should be greater than zero
   290  	if m.SetIsBootstrappedMock.mainExpectation != nil {
   291  		return atomic.LoadUint64(&m.SetIsBootstrappedCounter) > 0
   292  	}
   293  
   294  	// if func was set then invocations count should be greater than zero
   295  	if m.SetIsBootstrappedFunc != nil {
   296  		return atomic.LoadUint64(&m.SetIsBootstrappedCounter) > 0
   297  	}
   298  
   299  	return true
   300  }
   301  
   302  //ValidateCallCounters checks that all mocked methods of the interface have been called at least once
   303  //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
   304  func (m *SwitcherWorkAroundMock) ValidateCallCounters() {
   305  
   306  	if !m.IsBootstrappedFinished() {
   307  		m.t.Fatal("Expected call to SwitcherWorkAroundMock.IsBootstrapped")
   308  	}
   309  
   310  	if !m.SetIsBootstrappedFinished() {
   311  		m.t.Fatal("Expected call to SwitcherWorkAroundMock.SetIsBootstrapped")
   312  	}
   313  
   314  }
   315  
   316  //CheckMocksCalled checks that all mocked methods of the interface have been called at least once
   317  //Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
   318  func (m *SwitcherWorkAroundMock) CheckMocksCalled() {
   319  	m.Finish()
   320  }
   321  
   322  //Finish checks that all mocked methods of the interface have been called at least once
   323  //Deprecated: please use MinimockFinish or use Finish method of minimock.Controller
   324  func (m *SwitcherWorkAroundMock) Finish() {
   325  	m.MinimockFinish()
   326  }
   327  
   328  //MinimockFinish checks that all mocked methods of the interface have been called at least once
   329  func (m *SwitcherWorkAroundMock) MinimockFinish() {
   330  
   331  	if !m.IsBootstrappedFinished() {
   332  		m.t.Fatal("Expected call to SwitcherWorkAroundMock.IsBootstrapped")
   333  	}
   334  
   335  	if !m.SetIsBootstrappedFinished() {
   336  		m.t.Fatal("Expected call to SwitcherWorkAroundMock.SetIsBootstrapped")
   337  	}
   338  
   339  }
   340  
   341  //Wait waits for all mocked methods to be called at least once
   342  //Deprecated: please use MinimockWait or use Wait method of minimock.Controller
   343  func (m *SwitcherWorkAroundMock) Wait(timeout time.Duration) {
   344  	m.MinimockWait(timeout)
   345  }
   346  
   347  //MinimockWait waits for all mocked methods to be called at least once
   348  //this method is called by minimock.Controller
   349  func (m *SwitcherWorkAroundMock) MinimockWait(timeout time.Duration) {
   350  	timeoutCh := time.After(timeout)
   351  	for {
   352  		ok := true
   353  		ok = ok && m.IsBootstrappedFinished()
   354  		ok = ok && m.SetIsBootstrappedFinished()
   355  
   356  		if ok {
   357  			return
   358  		}
   359  
   360  		select {
   361  		case <-timeoutCh:
   362  
   363  			if !m.IsBootstrappedFinished() {
   364  				m.t.Error("Expected call to SwitcherWorkAroundMock.IsBootstrapped")
   365  			}
   366  
   367  			if !m.SetIsBootstrappedFinished() {
   368  				m.t.Error("Expected call to SwitcherWorkAroundMock.SetIsBootstrapped")
   369  			}
   370  
   371  			m.t.Fatalf("Some mocks were not called on time: %s", timeout)
   372  			return
   373  		default:
   374  			time.Sleep(time.Millisecond)
   375  		}
   376  	}
   377  }
   378  
   379  //AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled,
   380  //it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled())
   381  func (m *SwitcherWorkAroundMock) AllMocksCalled() bool {
   382  
   383  	if !m.IsBootstrappedFinished() {
   384  		return false
   385  	}
   386  
   387  	if !m.SetIsBootstrappedFinished() {
   388  		return false
   389  	}
   390  
   391  	return true
   392  }