[core-be-agent] fix type mismatch: return sqlmock.Sqlmock (interface), not *sqlmock.Sqlmock
sqlmock.New() returns (Sqlmock, error) where Sqlmock is the interface type, not a pointer. setupTestDB correctly returns sqlmock.Sqlmock (interface), but setupWorkspaceCrudTest and setupInstructionsTestDB incorrectly declared *sqlmock.Sqlmock (pointer to interface). In Go, *Interface is a distinct type from Interface — this would be a compile error. Root cause: copy-paste from setupWorkspaceCrudTest where the original author assumed *sqlmock.Sqlmock was the correct type. Fix: change both setup functions to return sqlmock.Sqlmock (interface) to match what sqlmock.New() actually returns. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
446ef9c467
commit
7ebdbe102c
@ -29,7 +29,7 @@ import (
|
||||
// and returns both the mock and a gin engine that uses it.
|
||||
// The caller MUST use the returned gin engine for BOTH route registration
|
||||
// AND for r.ServeHTTP — using a different engine for either step breaks routing.
|
||||
func setupInstructionsTestDB(t *testing.T) (*sqlmock.Sqlmock, *gin.Engine) {
|
||||
func setupInstructionsTestDB(t *testing.T) (sqlmock.Sqlmock, *gin.Engine) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
mockDB, mock, err := sqlmock.New()
|
||||
if err != nil {
|
||||
@ -51,7 +51,7 @@ func setupInstructionsTestDB(t *testing.T) (*sqlmock.Sqlmock, *gin.Engine) {
|
||||
// setupInstructionsTest is kept for backward compatibility with tests that
|
||||
// don't need a gin engine (pure validation helpers). All DB-dependent tests
|
||||
// should use setupInstructionsTestDB instead.
|
||||
func setupInstructionsTest(t *testing.T) (*sqlmock.Sqlmock, *gin.Engine) {
|
||||
func setupInstructionsTest(t *testing.T) (sqlmock.Sqlmock, *gin.Engine) {
|
||||
return setupInstructionsTestDB(t)
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ import (
|
||||
// - validateWorkspaceFields: newline rejection, YAML special chars, length.
|
||||
// - validateWorkspaceDir: absolute/relative, traversal, system paths.
|
||||
|
||||
func setupWorkspaceCrudTest(t *testing.T) (*sqlmock.Sqlmock, *gin.Engine) {
|
||||
func setupWorkspaceCrudTest(t *testing.T) (sqlmock.Sqlmock, *gin.Engine) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
mock := setupTestDB(t)
|
||||
r := gin.New()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user