github.com/Capventis/moq@v0.2.6-0.20220316100624-05dd47497214/example/mockpersonstore_test.go (about)

     1  // Code generated by moq; DO NOT EDIT.
     2  // github.com/matryer/moq
     3  
     4  package example
     5  
     6  import (
     7  	"context"
     8  	"sync"
     9  )
    10  
    11  // Ensure, that PersonStoreMock does implement PersonStore.
    12  // If this is not the case, regenerate this file with moq.
    13  var _ PersonStore = &PersonStoreMock{}
    14  
    15  // PersonStoreMock is a mock implementation of PersonStore.
    16  //
    17  // 	func TestSomethingThatUsesPersonStore(t *testing.T) {
    18  //
    19  // 		// make and configure a mocked PersonStore
    20  // 		mockedPersonStore := &PersonStoreMock{
    21  // 			CreateFunc: func(ctx context.Context, person *Person, confirm bool) error {
    22  // 				panic("mock out the Create method")
    23  // 			},
    24  // 			GetFunc: func(ctx context.Context, id string) (*Person, error) {
    25  // 				panic("mock out the Get method")
    26  // 			},
    27  // 		}
    28  //
    29  // 		// use mockedPersonStore in code that requires PersonStore
    30  // 		// and then make assertions.
    31  //
    32  // 	}
    33  type PersonStoreMock struct {
    34  	// CreateFunc mocks the Create method.
    35  	CreateFunc func(ctx context.Context, person *Person, confirm bool) error
    36  
    37  	// GetFunc mocks the Get method.
    38  	GetFunc func(ctx context.Context, id string) (*Person, error)
    39  
    40  	// calls tracks calls to the methods.
    41  	calls struct {
    42  		// Create holds details about calls to the Create method.
    43  		Create []struct {
    44  			// Ctx is the ctx argument value.
    45  			Ctx context.Context
    46  			// Person is the person argument value.
    47  			Person *Person
    48  			// Confirm is the confirm argument value.
    49  			Confirm bool
    50  		}
    51  		// Get holds details about calls to the Get method.
    52  		Get []struct {
    53  			// Ctx is the ctx argument value.
    54  			Ctx context.Context
    55  			// ID is the id argument value.
    56  			ID string
    57  		}
    58  	}
    59  	lockCreate sync.RWMutex
    60  	lockGet    sync.RWMutex
    61  }
    62  
    63  // Create calls CreateFunc.
    64  func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) error {
    65  	if mock.CreateFunc == nil {
    66  		panic("PersonStoreMock.CreateFunc: method is nil but PersonStore.Create was just called")
    67  	}
    68  	callInfo := struct {
    69  		Ctx     context.Context
    70  		Person  *Person
    71  		Confirm bool
    72  	}{
    73  		Ctx:     ctx,
    74  		Person:  person,
    75  		Confirm: confirm,
    76  	}
    77  	mock.lockCreate.Lock()
    78  	mock.calls.Create = append(mock.calls.Create, callInfo)
    79  	mock.lockCreate.Unlock()
    80  	return mock.CreateFunc(ctx, person, confirm)
    81  }
    82  
    83  // CreateCalls gets all the calls that were made to Create.
    84  // Check the length with:
    85  //     len(mockedPersonStore.CreateCalls())
    86  func (mock *PersonStoreMock) CreateCalls() []struct {
    87  	Ctx     context.Context
    88  	Person  *Person
    89  	Confirm bool
    90  } {
    91  	var calls []struct {
    92  		Ctx     context.Context
    93  		Person  *Person
    94  		Confirm bool
    95  	}
    96  	mock.lockCreate.RLock()
    97  	calls = mock.calls.Create
    98  	mock.lockCreate.RUnlock()
    99  	return calls
   100  }
   101  
   102  // Get calls GetFunc.
   103  func (mock *PersonStoreMock) Get(ctx context.Context, id string) (*Person, error) {
   104  	if mock.GetFunc == nil {
   105  		panic("PersonStoreMock.GetFunc: method is nil but PersonStore.Get was just called")
   106  	}
   107  	callInfo := struct {
   108  		Ctx context.Context
   109  		ID  string
   110  	}{
   111  		Ctx: ctx,
   112  		ID:  id,
   113  	}
   114  	mock.lockGet.Lock()
   115  	mock.calls.Get = append(mock.calls.Get, callInfo)
   116  	mock.lockGet.Unlock()
   117  	return mock.GetFunc(ctx, id)
   118  }
   119  
   120  // GetCalls gets all the calls that were made to Get.
   121  // Check the length with:
   122  //     len(mockedPersonStore.GetCalls())
   123  func (mock *PersonStoreMock) GetCalls() []struct {
   124  	Ctx context.Context
   125  	ID  string
   126  } {
   127  	var calls []struct {
   128  		Ctx context.Context
   129  		ID  string
   130  	}
   131  	mock.lockGet.RLock()
   132  	calls = mock.calls.Get
   133  	mock.lockGet.RUnlock()
   134  	return calls
   135  }