-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Cannot understand the difference in custom types #1042
Comments
You have primed your mock with an initialised Collection, possibly using the literal syntax: This will happen with non-custom slices and maps as well. This line is the source of the format: Line 811 in 6241f9a
Perhaps it could be changed to use the go syntax here also by adding this expectedFmt = fmt.Sprintf("(%[1]T=%#[1]v)", expected) For the OPYou need to prime the mock with a nil Collection, this is one way of doing that when your type is a map or a slice: package main
import (
"context"
"testing"
"github.com/stretchr/testify/mock"
)
type Collection map[string]int
type MockThing struct {
mock.Mock
}
func (m *MockThing) SchemaInspection(ctx context.Context, alias, name, logs string, collection Collection) {
m.Called(ctx, alias, name, logs, collection)
}
func TestCollection(t *testing.T) {
thing := &MockThing{}
thing.Test(t)
// Incorrect
thing.On("SchemaInspection",
mock.Anything,
"alias",
"db_name",
"invocation_logs",
Collection{},
).Return().Once()
thing.SchemaInspection(context.Background(), "alias", "db_name", "invocation_logs", nil)
// Correct
thing.On("SchemaInspection",
mock.Anything,
"alias",
"db_name",
"invocation_logs",
*new(Collection),
).Return().Once()
thing.SchemaInspection(context.Background(), "alias", "db_name", "invocation_logs", nil)
} |
When priming and calling a mock with an empty vs nil slice or map, the diff view showed two identical strings as being not equal. By using the go syntax it is always clear when one side is nil. The type is still needed to differentiate int64(7) from int32(7). closes stretchr#1042
When priming and calling a mock with an empty vs nil slice or map, the diff view showed two identical strings as being not equal. By using the go syntax it is always clear when one side is nil. The type is still needed to differentiate int64(7) from int32(7). closes stretchr#1042
When priming and calling a mock with an empty vs nil slice or map, the diff view showed two identical strings as being not equal. By using the go syntax it is always clear when one side is nil. The type is still needed to differentiate int64(7) from int32(7). closes stretchr#1042
When priming and calling a mock with an empty vs nil slice or map, the diff view showed two identical strings as being not equal. By using the go syntax it is always clear when one side is nil. The type is still needed to differentiate int64(7) from int32(7). closes stretchr#1042
@sharadregoti Do not post issues as screenshot. Copy-pasting code is not possible. In addition the contrast is very low on your snapshot and is hard to read for me. |
I have a custom type of map called as
collection
which ismap[string]Fields
. You can check the image for detailed info.When my test case failed, I am not able to understand the difference in the 4th argument clearly.
Types info
Test Case
The text was updated successfully, but these errors were encountered: