2016-11-16 13:47:49 +00:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/kolide"
|
2016-11-16 13:47:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAppendListOptionsToSQL(t *testing.T) {
|
|
|
|
sql := "SELECT * FROM app_configs"
|
|
|
|
opts := kolide.ListOptions{
|
|
|
|
OrderKey: "name",
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := appendListOptionsToSQL(sql, opts)
|
2017-03-21 19:13:12 +00:00
|
|
|
expected := "SELECT * FROM app_configs ORDER BY name ASC LIMIT 100000"
|
2016-11-16 13:47:49 +00:00
|
|
|
if actual != expected {
|
|
|
|
t.Error("Expected", expected, "Actual", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = "SELECT * FROM app_configs"
|
|
|
|
opts.OrderDirection = kolide.OrderDescending
|
|
|
|
actual = appendListOptionsToSQL(sql, opts)
|
2017-03-21 19:13:12 +00:00
|
|
|
expected = "SELECT * FROM app_configs ORDER BY name DESC LIMIT 100000"
|
2016-11-16 13:47:49 +00:00
|
|
|
if actual != expected {
|
|
|
|
t.Error("Expected", expected, "Actual", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
opts = kolide.ListOptions{
|
|
|
|
PerPage: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = "SELECT * FROM app_configs"
|
|
|
|
actual = appendListOptionsToSQL(sql, opts)
|
|
|
|
expected = "SELECT * FROM app_configs LIMIT 10"
|
|
|
|
if actual != expected {
|
|
|
|
t.Error("Expected", expected, "Actual", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = "SELECT * FROM app_configs"
|
|
|
|
opts.Page = 2
|
|
|
|
actual = appendListOptionsToSQL(sql, opts)
|
|
|
|
expected = "SELECT * FROM app_configs LIMIT 10 OFFSET 20"
|
|
|
|
if actual != expected {
|
|
|
|
t.Error("Expected", expected, "Actual", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
opts = kolide.ListOptions{}
|
|
|
|
sql = "SELECT * FROM app_configs"
|
|
|
|
actual = appendListOptionsToSQL(sql, opts)
|
2017-03-21 19:13:12 +00:00
|
|
|
expected = "SELECT * FROM app_configs LIMIT 100000"
|
2016-11-16 13:47:49 +00:00
|
|
|
|
|
|
|
if actual != expected {
|
|
|
|
t.Error("Expected", expected, "Actual", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|