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

Add test for controlsvc.go #1097

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pkg/controlsvc/controlsvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func TestRunControlSvc(t *testing.T) {
mockNetceptor := mock_controlsvc.NewMockNetceptorForControlsvc(ctrl)
mockUnix := mock_controlsvc.NewMockUtiler(ctrl)
mockNet := mock_controlsvc.NewMockNeter(ctrl)
mockTLS := mock_controlsvc.NewMockTlser(ctrl)
mockListener := mock_controlsvc.NewMockListener(ctrl)

logger := logger.NewReceptorLogger("")

runControlSvcTestCases := []struct {
name string
Expand Down Expand Up @@ -158,6 +162,21 @@ func TestRunControlSvc(t *testing.T) {
"tcpListen": "",
},
},
{
name: "tcp listener set",
expectedError: "",
expectedCalls: func() {
mockNet.EXPECT().Listen(gomock.Any(), gomock.Any()).Return(mockListener, nil)
mockTLS.EXPECT().NewListener(gomock.Any(), gomock.Any()).Return(mockListener)
mockNetceptor.EXPECT().GetLogger().Return(logger).AnyTimes()
mockListener.EXPECT().Accept().Return(nil, errors.New("normal close")).AnyTimes()
},
listeners: map[string]string{
"service": "",
"unixSocket": "",
"tcpListen": "tcp:1",
},
},
}

for _, testCase := range runControlSvcTestCases {
Expand All @@ -166,10 +185,11 @@ func TestRunControlSvc(t *testing.T) {
s := controlsvc.New(false, mockNetceptor)
s.SetServerUtils(mockUnix)
s.SetServerNet(mockNet)
s.SetServerTLS(mockTLS)

err := s.RunControlSvc(context.Background(), testCase.listeners["service"], &tls.Config{}, testCase.listeners["unixSocket"], os.FileMode(0o600), testCase.listeners["tcpListen"], &tls.Config{})

if err.Error() != testCase.expectedError {
if err != nil && err.Error() != testCase.expectedError {
t.Errorf("expected error %s, got %v", testCase.expectedError, err)
}
})
Expand Down
Loading