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