Skip to content

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