Copilot commented on code in PR #980: URL: https://github.com/apache/incubator-seata-go/pull/980#discussion_r2504414003
########## pkg/remoting/mock/mock_getty_session_test.go: ########## @@ -0,0 +1,760 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package mock + +import ( + "errors" + "net" + "testing" + "time" + + getty "github.com/apache/dubbo-getty" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" +) + +// mockConn is a mock implementation of net.Conn for testing +type mockConn struct { + net.Conn +} + +func (m *mockConn) Read(b []byte) (n int, err error) { return 0, nil } +func (m *mockConn) Write(b []byte) (n int, err error) { return len(b), nil } +func (m *mockConn) Close() error { return nil } +func (m *mockConn) LocalAddr() net.Addr { return &net.TCPAddr{} } +func (m *mockConn) RemoteAddr() net.Addr { return &net.TCPAddr{} } +func (m *mockConn) SetDeadline(t time.Time) error { return nil } +func (m *mockConn) SetReadDeadline(t time.Time) error { return nil } +func (m *mockConn) SetWriteDeadline(t time.Time) error { return nil } + +// mockEndPoint is a mock implementation of getty.EndPoint +type mockEndPoint struct { + getty.EndPoint +} + +// mockEventListener is a mock implementation of getty.EventListener +type mockEventListener struct { + getty.EventListener +} + +// mockReadWriter is a mock implementation of getty.ReadWriter +type mockReadWriter struct { + getty.ReadWriter +} + +// mockReader is a mock implementation of getty.Reader +type mockReader struct { + getty.Reader +} + +// mockWriter is a mock implementation of getty.Writer +type mockWriter struct { + getty.Writer +} + +// mockSession is a mock implementation of getty.Session +type mockSession struct { + getty.Session +} + +func TestNewMockTestSession(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mock := NewMockTestSession(ctrl) + assert.NotNil(t, mock, "NewMockTestSession should return a non-nil mock") + assert.NotNil(t, mock.ctrl, "Mock should have a controller") + assert.NotNil(t, mock.recorder, "Mock should have a recorder") Review Comment: These assertions test internal implementation details (unexported fields `ctrl` and `recorder`) rather than behavior. Testing internal state is generally considered a bad practice. Other similar test files in this codebase (e.g., `mock_driver_test.go`, `mock_datasource_manager_test.go`) only assert that the mock and its EXPECT() method are non-nil, without checking internal fields. Consider removing these assertions or keeping only the first assertion at line 80. ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
