mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-31 08:44:25 +00:00
Initial analysis: identified bug in AddTablePrefixToColumns
Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com>
This commit is contained in:
63
pkg/common/test_addprefix_test.go
Normal file
63
pkg/common/test_addprefix_test.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddTablePrefixToColumns_BugRepro(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
where string
|
||||
tableName string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "SQL literal true - should not add prefix",
|
||||
where: "true",
|
||||
tableName: "mastertask",
|
||||
expected: "true",
|
||||
},
|
||||
{
|
||||
name: "SQL literal TRUE uppercase - should not add prefix",
|
||||
where: "TRUE",
|
||||
tableName: "mastertask",
|
||||
expected: "TRUE",
|
||||
},
|
||||
{
|
||||
name: "SQL literal false - should not add prefix",
|
||||
where: "false",
|
||||
tableName: "mastertask",
|
||||
expected: "false",
|
||||
},
|
||||
{
|
||||
name: "SQL literal null - should not add prefix",
|
||||
where: "null",
|
||||
tableName: "mastertask",
|
||||
expected: "null",
|
||||
},
|
||||
{
|
||||
name: "SQL literal NULL uppercase - should not add prefix",
|
||||
where: "NULL",
|
||||
tableName: "mastertask",
|
||||
expected: "NULL",
|
||||
},
|
||||
{
|
||||
name: "Multiple true conditions",
|
||||
where: "true AND true",
|
||||
tableName: "mastertask",
|
||||
expected: "true AND true",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := AddTablePrefixToColumns(tt.where, tt.tableName)
|
||||
if result != tt.expected {
|
||||
t.Errorf("AddTablePrefixToColumns(%q, %q) = %q; want %q", tt.where, tt.tableName, result, tt.expected)
|
||||
} else {
|
||||
fmt.Printf("✓ Test passed: %s\n", tt.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
51
pkg/common/test_unregistered_test.go
Normal file
51
pkg/common/test_unregistered_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddTablePrefixToColumns_UnregisteredModel(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
where string
|
||||
tableName string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "SQL literal true with unregistered model - should not add prefix",
|
||||
where: "true",
|
||||
tableName: "unregistered_table",
|
||||
expected: "true",
|
||||
},
|
||||
{
|
||||
name: "SQL literal false with unregistered model - should not add prefix",
|
||||
where: "false",
|
||||
tableName: "unregistered_table",
|
||||
expected: "false",
|
||||
},
|
||||
{
|
||||
name: "SQL literal null with unregistered model - should not add prefix",
|
||||
where: "null",
|
||||
tableName: "unregistered_table",
|
||||
expected: "null",
|
||||
},
|
||||
{
|
||||
name: "Valid column with unregistered model - should not add prefix (no validation)",
|
||||
where: "status = 'active'",
|
||||
tableName: "unregistered_table",
|
||||
expected: "unregistered_table.status = 'active'",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := AddTablePrefixToColumns(tt.where, tt.tableName)
|
||||
if result != tt.expected {
|
||||
t.Errorf("AddTablePrefixToColumns(%q, %q) = %q; want %q", tt.where, tt.tableName, result, tt.expected)
|
||||
} else {
|
||||
fmt.Printf("✓ Test passed: %s\n", tt.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user