mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-09-27 10:02:10 +08:00
chore: move util/sql to pkg/util/sql
This commit is contained in:
48
pkg/util/sql/sql_test.go
Normal file
48
pkg/util/sql/sql_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package sql
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_FormatSelect_Columns_NoData(t *testing.T) {
|
||||
result := FormatColumnSelect([]string{})
|
||||
|
||||
assert.Equal(t, len(result), 0)
|
||||
}
|
||||
|
||||
func Test_FormatSelect_Columns(t *testing.T) {
|
||||
result := FormatColumnSelect([]string{"name", "uid"})
|
||||
|
||||
assert.Equal(t, len(result), 2)
|
||||
|
||||
for _, item := range result {
|
||||
if item != "name" && item != "uid" {
|
||||
t.Error("item not in possible list")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FormatSelect_Alias(t *testing.T) {
|
||||
result := FormatColumnSelect([]string{"name", "uid"}, "u")
|
||||
|
||||
assert.Equal(t, len(result), 2)
|
||||
|
||||
for _, item := range result {
|
||||
if item != "u.name" && item != "u.uid" {
|
||||
t.Error("item not in possible list")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FormatSelect_AliasDestination(t *testing.T) {
|
||||
result := FormatColumnSelect([]string{"name", "uid"}, "u", "user")
|
||||
|
||||
assert.Equal(t, len(result), 2)
|
||||
|
||||
for _, item := range result {
|
||||
if item != `u.name "user.name"` && item != `u.uid "user.uid"` {
|
||||
t.Error("item not in possible list")
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user