Error with go mock when using constants

Hi,

I have a function which takes a struct as argument. This struct contains int64 variables.

I have used go mock for mocking unitest cases.

But the problem is when I pass int64 variables it says Got and Want are different at function level.(In arguments).

Running tool: /usr/local/go/bin/go test -timeout 30s -run ^Test_queryResolver_SellersByStatus$ query/gty_qry_bo/graph

=== RUN Test_queryResolver_SellersByStatus
=== RUN Test_queryResolver_SellersByStatus/TestCase_1
sam_id:"2" status:"PFA" per_page:2 page_no:1 count:true
=== CONT Test_queryResolver_SellersByStatus
graph/schema.resolvers.go:56: Unexpected call to *mocks.MockBoQueryClient.GetSellersByStatus([context.Background sam_id:"2" status:"PFA" per_page:2 page_no:1 count:true]) at gty_qry_bo/graph/schema.resolvers.go:56 because:
expected call at /gty_qry_bo/graph/internal_schema.resolvers_test.go:52 doesn't match the argument at index 1.
Got: sam_id:"2" status:"PFA" per_page:2 page_no:1 count:true (*generated.SellersByStatusRequest)
Want: is equal to sam_id:"2" status:"PFA" per_page:2 page_no:1 count:true (*generated.SellersByStatusRequest)
expected call at /graph/internal_schema.resolvers_test.go:64 doesn't match the argument at index 1.
Got: sam_id:"2" status:"PFA" per_page:2 page_no:1 count:true (*generated.SellersByStatusRequest)
Want: is equal to sam_id:"2" status:"PFA" per_page:2 page_no:2 count:true (*generated.SellersByStatusRequest)
=== CONT Test_queryResolver_SellersByStatus/TestCase_1
/graph/testing.go:1169: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
=== CONT Test_queryResolver_SellersByStatus
gty_qry_bo/graph/controller.go:137: missing call(s) to *mocks.MockBoQueryClient.GetSellersByStatus(is equal to context.Background (*context.emptyCtx), is equal to sam_id:"2" status:"PFA" per_page:2 page_no:1 count:true (*generated.SellersByStatusRequest)) gty_qry_bo/graph/internal_schema.resolvers_test.go:52
gty_qry_bo/graph/controller.go:137: missing call(s) to *mocks.MockBoQueryClient.GetSellersByStatus(is equal to context.Background (*context.emptyCtx), is equal to sam_id:"2" status:"PFA" per_page:2 page_no:2 count:true (*generated.SellersByStatusRequest)) gty_qry_bo/graph/internal_schema.resolvers_test.go:64
gty_qry_bo/graph/controller.go:137: aborting test due to missing call(s)
--- FAIL: Test_queryResolver_SellersByStatus (0.00s)
--- FAIL: Test_queryResolver_SellersByStatus/TestCase_1 (0.00s)
FAIL
FAIL gateway_msvc/query/gty_qry_bo/graph 0.464s

But test cases are passed when I add fmt.Println(arg1) in Recorder function.
Does fmt.Println does any thing?

Running tool: /usr/local/go/bin/go test -timeout 30s -run ^Test_queryResolver_SellersByStatus$ golang/gateway_msvc/query/gty_qry_bo/graph

=== RUN   Test_queryResolver_SellersByStatus
sam_id:"2"  status:"PFA"  per_page:2  page_no:1  count:true
sam_id:"2"  status:"PFA"  per_page:2  page_no:2  count:true
=== RUN   Test_queryResolver_SellersByStatus/TestCase_1
sam_id:"2"  status:"PFA"  per_page:2  page_no:1  count:true
=== RUN   Test_queryResolver_SellersByStatus/TestCase_2
sam_id:"2"  status:"PFA"  per_page:2  page_no:2  count:true
--- PASS: Test_queryResolver_SellersByStatus (0.00s)
    --- PASS: Test_queryResolver_SellersByStatus/TestCase_1 (0.00s)
    --- PASS: Test_queryResolver_SellersByStatus/TestCase_2 (0.00s)
PASS
ok    golang/gateway_msvc/query/gty_qry_bo/graph  0.415s

Thanks,
Akhil

If I change the param type of arg1 to my struct type from interface{}

It works fine.

But How it works if I just add fmt.Println() without changing the param type?

It is good to change the DO NOT EDIT file to fix this issue?

Thanks,
Akhil

Can you share an example of the actual code? I can’t think of any reason off the top of my head how any of the fmt.Print “family” of functions would change any of their parameters, but if you show your code, we can provide more information.

Actual Function:-

// GetSellersByStatus indicates an expected call of GetSellersByStatus.
func (mr *MockBoQueryClientMockRecorder) GetSellersByStatus(arg0,arg1 interface{}, arg2 ...interface{}) *gomock.Call {
	mr.mock.ctrl.T.Helper()
	varargs := append([]interface{}{arg0, arg1}, arg2...)
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSellersByStatus", reflect.TypeOf((*MockBoQueryClient)(nil).GetSellersByStatus), varargs...)
}

It worked if I change the param type or add add print in that without Param.
Modified Function : -

// GetSellersByStatus indicates an expected call of GetSellersByStatus.
func (mr *MockBoQueryClientMockRecorder) GetSellersByStatus(arg0 interface{}, arg1 *generated.SellersByStatusRequest, arg2 ...interface{}) *gomock.Call {
	mr.mock.ctrl.T.Helper()
//fmt.Println(arg1)
	varargs := append([]interface{}{arg0, arg1}, arg2...)
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSellersByStatus", reflect.TypeOf((*MockBoQueryClient)(nil).GetSellersByStatus), varargs...)
}

Sorry for the late reply

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.