matryer / moq

Interface mocking tool for go generate
http://bit.ly/meetmoq
MIT License
2k stars 127 forks source link

Bug: `-with-resets` does not support interfaces with Generics #228

Closed andrewradamis-vividseats closed 1 week ago

andrewradamis-vividseats commented 1 week ago

-with-resets is currently generating Reset{{.Name}}Calls() and ResetCalls() without Generic Types

//go:generate moq -with-resets -out ./mock.go  ResetStoreGeneric
type ResetStoreGeneric[T, S any] interface {
    Get(ctx context.Context, id T) (string, error)
    Create(ctx context.Context, id T, value S) error
}

Generates

// ResetCreateCalls reset all the calls that were made to Create.
func (mock *ResetStoreGenericMock) ResetCreateCalls() {
    mock.lockCreate.Lock()
    mock.calls.Create = nil
    mock.lockCreate.Unlock()
}

// ResetGetCalls reset all the calls that were made to Get.
func (mock *ResetStoreGenericMock) ResetGetCalls() {
    mock.lockGet.Lock()
    mock.calls.Get = nil
    mock.lockGet.Unlock()
}

// ResetCalls reset all the calls that were made to all mocked methods.
func (mock *ResetStoreGenericMock) ResetCalls() {
    mock.lockCreate.Lock()
    mock.calls.Create = nil
    mock.lockCreate.Unlock()

    mock.lockGet.Lock()
    mock.calls.Get = nil
    mock.lockGet.Unlock()
}

Instead of expected:

// ResetCreateCalls reset all the calls that were made to Create.
func (mock *ResetStoreGenericMock[T, S]) ResetCreateCalls() {
    mock.lockCreate.Lock()
    mock.calls.Create = nil
    mock.lockCreate.Unlock()
}

// ResetGetCalls reset all the calls that were made to Get.
func (mock *ResetStoreGenericMock[T, S]) ResetGetCalls() {
    mock.lockGet.Lock()
    mock.calls.Get = nil
    mock.lockGet.Unlock()
}

// ResetCalls reset all the calls that were made to all mocked methods.
func (mock *ResetStoreGenericMock[T, S]) ResetCalls() {
    mock.lockCreate.Lock()
    mock.calls.Create = nil
    mock.lockCreate.Unlock()

    mock.lockGet.Lock()
    mock.calls.Get = nil
    mock.lockGet.Unlock()
}