Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method naming conflict with Field and FieldNot. #30

Open
alan-mcnaney opened this issue Oct 3, 2018 · 1 comment
Open

Method naming conflict with Field and FieldNot. #30

alan-mcnaney opened this issue Oct 3, 2018 · 1 comment
Assignees
Labels

Comments

@alan-mcnaney
Copy link

Similarly named methods can cause auto-generated method naming conflicts. Specifically if an interface has a naming such as:

Field(string, interface{})
FieldNot(string, interface{})

While charlatan does code generation for Field(), it generates FieldCalled() and FieldNotCalled().

When charlatan attempts to generate methods for FieldNot(), it will generate FieldNotCalled() and draw a method definition naming conflict error, as there is already a FieldNotCalled() method defined by code generation for Field().

@kevinbirch
Copy link
Contributor

I was browsing this project and thought I'd leave a note about one approach to solving this:

Using the example from the README:

type FakeService struct {
	QueryHook func(*QueryFilter) ([]*Thing, error)

	QueryCalls []*QueryInvocation
}

You could add a type for the invocation array, and move the query methods there:

type QueryInvocations []*QueryInvocation

func (i QueryInvocations) Called() bool {
	return len(i) != 0
}

func (i QueryInvocations) AssertCalled(t *testing.T) {
	t.Helper()
	 if len(i) == 0 {
		t.Error("FakeService.Query not called, expected at least one")
	}
}

// etc ...

type FakeService struct {
	QueryHook func(*QueryFilter) ([]*Thing, error)

	QueryCalls QueryInvocations
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants