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

Generate a struct to assert Calls #217

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

joseboretto
Copy link

Problem

When you need to assert the call, you have to copy/duplicate the "Calls" struct.

Example

	// When
	s.GetPerson(ctx, "1")
	// Then
	actual := personStore.GetCalls()
	expected := []struct {
		Ctx context.Context
		ID  string
	}{
		{
			Ctx: ctx,
			ID:  "1",
		},
	}
	if !reflect.DeepEqual(expected, actual) {
		t.Fatalf("Expected %v but got %v", expected, actual)
	}

Solution

Create the "Calls" struct as an independent struct

Example

	// When
	s.GetPerson(ctx, "1")
	// Then
	actual := personStore.GetCalls()
	expected := []PersonStoreMockGetCalls{
		{
			Ctx: ctx,
			ID:  "1",
		},
	}
	if !reflect.DeepEqual(expected, actual) {
		t.Fatalf("Expected %v but got %v", expected, actual)
	}

Extra

  • Move the template to a template file. The extension of the file enables the syntax highlighting of the template.

For Go templates, the commonly used file extensions are:

  • .gohtml:

https://www.jetbrains.com/help/idea/integration-with-go-templates.html

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

Successfully merging this pull request may close these issues.

2 participants