From 0f42d2b9ed29640e3f62ebab302cc6e50eff9571 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Mon, 3 May 2021 21:14:08 +0200 Subject: [PATCH] fix query tests After the query API was a bit adjusted, the tests weren't fixed. --- query/query_test.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/query/query_test.go b/query/query_test.go index d07c9c4..04ea498 100644 --- a/query/query_test.go +++ b/query/query_test.go @@ -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) }