2024-08-09 15:00:52 +00:00
|
|
|
package builder
|
2024-08-09 14:14:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConvertFieldsBool(t *testing.T) {
|
2024-08-09 22:33:10 +00:00
|
|
|
result, err := convertFields([]Map{
|
2024-08-09 14:14:42 +00:00
|
|
|
{"test": true},
|
|
|
|
{"test2": false},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if result != `test` {
|
|
|
|
t.Errorf("Expected test, got %s", result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConvertFieldsInt(t *testing.T) {
|
2024-08-09 22:33:10 +00:00
|
|
|
result, err := convertFields([]Map{
|
2024-08-09 14:14:42 +00:00
|
|
|
{"test": 0},
|
|
|
|
{"test2": 1},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if result != `test2` {
|
|
|
|
t.Errorf("Expected test, got %s", result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConvertFieldsStr(t *testing.T) {
|
2024-08-09 22:33:10 +00:00
|
|
|
result, err := convertFields([]Map{
|
2024-08-09 14:14:42 +00:00
|
|
|
{"t.test": "Test"},
|
|
|
|
{"SUM(t.test, t.int)": "Sum"},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if result != `t.test AS Test, SUM(t.test, t.int) AS Sum` {
|
|
|
|
t.Errorf("Expected test, got %s", result)
|
|
|
|
}
|
|
|
|
}
|