fix query tests
After the query API was a bit adjusted, the tests weren't fixed.
This commit is contained in:
parent
849ce2d791
commit
0f42d2b9ed
|
@ -8,17 +8,20 @@ import (
|
||||||
|
|
||||||
func TestFieldListToSelect(t *testing.T) {
|
func TestFieldListToSelect(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
table string
|
||||||
names types.FieldList
|
names types.FieldList
|
||||||
mapping map[string]string
|
mapping map[string]string
|
||||||
out 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"),
|
types.NewFieldList("foo", "bar", "baz"),
|
||||||
map[string]string{"foo": "c.foo", "bar": "b.bar"},
|
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"),
|
types.NewFieldList("subnets", "vlan", "name"),
|
||||||
map[string]string{"subnets": "s.subnets", "vlan": "vlan.vlan_id", "name": "p.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",
|
"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 {
|
for _, test := range tests {
|
||||||
out := FieldListToSelect(test.names, test.mapping)
|
out := FieldListToSelect(test.table, test.names, test.mapping)
|
||||||
if out != test.out {
|
if out != test.out {
|
||||||
t.Errorf("expected `%s`, got `%s`", test.out, out)
|
t.Errorf("expected `%s`, got `%s`", test.out, out)
|
||||||
}
|
}
|
||||||
|
@ -35,16 +38,17 @@ func TestFieldListToSelect(t *testing.T) {
|
||||||
|
|
||||||
func TestNameToAttrPath(t *testing.T) {
|
func TestNameToAttrPath(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
table string
|
||||||
in string
|
in string
|
||||||
out string
|
out string
|
||||||
}{
|
}{
|
||||||
{"foo", `attributes->'foo'`},
|
{"zoo", "foo", `zoo.attributes->'foo'`},
|
||||||
{"foo.bar", `attributes->'foo'->'bar'`},
|
{"zoo", "foo.bar", `zoo.attributes->'foo'->'bar'`},
|
||||||
{"", `attributes`},
|
{"zoo", "", `zoo.attributes`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
out := nameToAttrPath(test.in)
|
out := nameToAttrPath(test.table, test.in)
|
||||||
if test.out != out {
|
if test.out != out {
|
||||||
t.Errorf("expected `%s`, got `%s`", test.out, out)
|
t.Errorf("expected `%s`, got `%s`", test.out, out)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue