fix query tests

After the query API was a bit adjusted, the tests weren't fixed.
This commit is contained in:
Gibheer 2021-05-03 21:14:08 +02:00
parent 849ce2d791
commit 0f42d2b9ed
1 changed files with 13 additions and 9 deletions

View File

@ -8,17 +8,20 @@ import (
func TestFieldListToSelect(t *testing.T) {
tests := []struct {
table string
names types.FieldList
mapping map[string]string
out string
}{
{types.NewFieldList("name"), map[string]string{"name": "name"}, "name as name"},
{"foo", types.NewFieldList("name"), map[string]string{"name": "name"}, "name as name"},
{
"foo",
types.NewFieldList("foo", "bar", "baz"),
map[string]string{"foo": "c.foo", "bar": "b.bar"},
"b.bar as bar,attributes->'baz' as baz,c.foo as foo",
"b.bar as bar,foo.attributes->'baz' as baz,c.foo as foo",
},
{
"foo",
types.NewFieldList("subnets", "vlan", "name"),
map[string]string{"subnets": "s.subnets", "vlan": "vlan.vlan_id", "name": "p.name"},
"p.name as name,s.subnets as subnets,vlan.vlan_id as vlan",
@ -26,7 +29,7 @@ func TestFieldListToSelect(t *testing.T) {
}
for _, test := range tests {
out := FieldListToSelect(test.names, test.mapping)
out := FieldListToSelect(test.table, test.names, test.mapping)
if out != test.out {
t.Errorf("expected `%s`, got `%s`", test.out, out)
}
@ -35,16 +38,17 @@ func TestFieldListToSelect(t *testing.T) {
func TestNameToAttrPath(t *testing.T) {
tests := []struct {
in string
out string
table string
in string
out string
}{
{"foo", `attributes->'foo'`},
{"foo.bar", `attributes->'foo'->'bar'`},
{"", `attributes`},
{"zoo", "foo", `zoo.attributes->'foo'`},
{"zoo", "foo.bar", `zoo.attributes->'foo'->'bar'`},
{"zoo", "", `zoo.attributes`},
}
for _, test := range tests {
out := nameToAttrPath(test.in)
out := nameToAttrPath(test.table, test.in)
if test.out != out {
t.Errorf("expected `%s`, got `%s`", test.out, out)
}