Copilot commented on code in PR #972: URL: https://github.com/apache/incubator-seata-go/pull/972#discussion_r2487084415
########## pkg/datasource/sql/undo/factor/undo_executor_holder_factor_test.go: ########## @@ -0,0 +1,97 @@ +/* + * 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 factor + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "seata.apache.org/seata-go/pkg/datasource/sql/types" +) + +func TestGetUndoExecutorHolder_MySQL(t *testing.T) { + // Test getting MySQL undo executor holder + holder, err := GetUndoExecutorHolder(types.DBTypeMySQL) + + assert.NoError(t, err) + assert.NotNil(t, holder) +} + +func TestGetUndoExecutorHolder_UnsupportedDBType(t *testing.T) { + // Test unsupported database types + testCases := []struct { + name string + dbType types.DBType + }{ + {"Unknown", types.DBTypeUnknown}, + {"PostgreSQL", types.DBTypePostgreSQL}, + {"SQLServer", types.DBTypeSQLServer}, + {"Oracle", types.DBTypeOracle}, + {"MariaDB", types.DBTypeMARIADB}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + holder, err := GetUndoExecutorHolder(tc.dbType) + + assert.Error(t, err) + assert.Nil(t, holder) + assert.Equal(t, ErrNotImplDBType, err) + }) + } +} + +func TestGetUndoExecutorHolder_LazyInit(t *testing.T) { + // Reset the map to test lazy initialization + undoExecutorHolderMap = nil Review Comment: Resetting the package-level variable `undoExecutorHolderMap` to nil can cause race conditions if tests run in parallel. Consider using `t.Parallel()` guard or test isolation mechanisms to prevent concurrent access to this shared state. ########## pkg/datasource/sql/undo/factor/undo_executor_holder_factor_test.go: ########## @@ -0,0 +1,97 @@ +/* + * 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 factor + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "seata.apache.org/seata-go/pkg/datasource/sql/types" +) + +func TestGetUndoExecutorHolder_MySQL(t *testing.T) { + // Test getting MySQL undo executor holder + holder, err := GetUndoExecutorHolder(types.DBTypeMySQL) + + assert.NoError(t, err) + assert.NotNil(t, holder) +} + +func TestGetUndoExecutorHolder_UnsupportedDBType(t *testing.T) { + // Test unsupported database types + testCases := []struct { + name string + dbType types.DBType + }{ + {"Unknown", types.DBTypeUnknown}, + {"PostgreSQL", types.DBTypePostgreSQL}, + {"SQLServer", types.DBTypeSQLServer}, + {"Oracle", types.DBTypeOracle}, + {"MariaDB", types.DBTypeMARIADB}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + holder, err := GetUndoExecutorHolder(tc.dbType) + + assert.Error(t, err) + assert.Nil(t, holder) + assert.Equal(t, ErrNotImplDBType, err) + }) + } +} + +func TestGetUndoExecutorHolder_LazyInit(t *testing.T) { + // Reset the map to test lazy initialization + undoExecutorHolderMap = nil + + holder1, err1 := GetUndoExecutorHolder(types.DBTypeMySQL) + assert.NoError(t, err1) + assert.NotNil(t, holder1) + + holder2, err2 := GetUndoExecutorHolder(types.DBTypeMySQL) + assert.NoError(t, err2) + assert.NotNil(t, holder2) + assert.IsType(t, holder1, holder2) +} + +func TestGetUndoExecutorHolder_MapNotNil(t *testing.T) { + // Ensure the map is initialized + _, _ = GetUndoExecutorHolder(types.DBTypeMySQL) + Review Comment: The blank identifiers suggest these return values are intentionally ignored, but the test doesn't verify that the map is properly initialized by this call. Consider adding `require.NoError(t, err)` to ensure the initialization succeeds before asserting on the map state. ```suggestion _, err := GetUndoExecutorHolder(types.DBTypeMySQL) assert.NoError(t, err) ``` -- 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]
