github.com/braveheart12/insolar-09-08-19@v0.8.7/ledger/storage/nodes/setter_mock.go (about)

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