-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat(evpn unit test): adding evpn mock unit test #276
Conversation
atulpatel261194
commented
Aug 27, 2023
1e76d3b
to
fa8597e
Compare
Signed-off-by: atulpatel261194 <[email protected]>
fa8597e
to
0f87fb7
Compare
Codecov Report
@@ Coverage Diff @@
## main #276 +/- ##
=====================================
Coverage 8.07% 8.07%
=====================================
Files 13 13
Lines 2006 2006
=====================================
Hits 162 162
Misses 1826 1826
Partials 18 18 |
Signed-off-by: atulpatel261194 <[email protected]>
0f87fb7
to
06847d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
mockEvpnClient.On("DeleteBridgePort", mock.Anything, mock.Anything, mock.Anything). | ||
Return(nil, expectedError) | ||
|
||
resultResponse, err := mockEvpnClient.DeleteBridgePort(context.TODO(), "bp1", true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atulpatel261194 A bit late, but why do you test the generated mock here in these tests? Testing of mocks adds little value to our test suite.
I think we should test the implementation(evpnClientImpl) calls a corresponding method in pb.BridgePortServiceClient instead...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artek-koltun testing the generated mocks protects the changes in .proto files.
i believe we can't test the real api's which create, delete and update different port, bridge, svi and vrf. if there is any way i can test these api's directly Please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually a way. You can use dependency injection to replace the real connection components. The test would look like
func TestCreateBridgePortSuccess(t *testing.T) {
wantRequest := &_go.CreateBridgePortRequest{
BridgePortId: "bp1",
BridgePort: &pb.BridgePort{
Spec: &pb.BridgePortSpec{
MacAddress: []byte("00:11:22:aa:bb:cc"), // Is it valid approach? Should we use net.ParseMac()?
Ptype: _go.BridgePortType_ACCESS,
LogicalBridges: []string{"lb1", "lb2"},
},
},
}
wantResponse := wantRequest.BridgePort
mockClient := mocks.NewBridgePortServiceClient(t)
mockClient.EXPECT().CreateBridgePort(mock.Anything, wantRequest).
Return(proto.Clone(wantResponse).(*pb.BridgePort), nil)
connClosed := false
mockConn := mocks.NewConnector(t)
mockConn.EXPECT().NewConn().Return(
&grpc.ClientConn{},
func() { connClosed = true },
nil,
)
c, _ := network.NewBridgePortWithArgs(
mockConn,
func(grpc.ClientConnInterface) pb.BridgePortServiceClient {
return mockClient
},
)
response, err := c.CreateBridgePort(
context.Background(),
"bp1", "00:11:22:aa:bb:cc", "access", []string{"lb1", "lb2"},
)
assert.NoError(t, err)
assert.True(t, proto.Equal(response, wantResponse))
assert.Equal(t, true, connClosed)
}
Here you can see how I tested nvme subsystem with the table approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artek-koltun Sure, i will update the test cases. thank you for the inputs