github.com/Axway/agent-sdk@v1.1.101/pkg/apic/apiserver/clients/api/v1/query_test.go (about) 1 package v1 2 3 import ( 4 "testing" 5 6 management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1" 7 ) 8 9 func TestRSQL(t *testing.T) { 10 testCases := []struct { 11 name string 12 input QueryNode 13 expected string 14 }{ 15 { 16 "one attribute, one value", 17 AttrIn("a", "v"), 18 `attributes.a=="v"`, 19 }, 20 { 21 "one attribute, two values", 22 AttrIn("a", "v1", "v2"), 23 `attributes.a=in=("v1","v2")`, 24 }, 25 { 26 "one tag", 27 TagsIn("t"), 28 `tags=="t"`, 29 }, 30 { 31 "three tags", 32 TagsIn("t1", "t2", "t3"), 33 `tags=in=("t1","t2","t3")`, 34 }, 35 { 36 "one attribute, two values ored with three tags", 37 Or(AttrIn("a", "v1", "v2"), TagsIn("t1", "t2", "t3")), 38 `(attributes.a=in=("v1","v2"),tags=in=("t1","t2","t3"))`, 39 }, 40 { 41 "one attribute, one values anded with three tags", 42 And(AttrIn("a", "v1"), TagsIn("t1", "t2", "t3")), 43 `(attributes.a=="v1";tags=in=("t1","t2","t3"))`, 44 }, 45 { 46 "all two attributes", 47 AllAttr(map[string]string{"a1": "v1", "a2": "v2"}), 48 `(attributes.a1=="v1";attributes.a2=="v2")`, 49 }, 50 { 51 "any three attributes", 52 AnyAttr(map[string]string{"a1": "v1", "a2": "v2", "a3": "v3"}), 53 `(attributes.a1=="v1",attributes.a2=="v2",attributes.a3=="v3")`, 54 }, 55 { 56 "by reference", 57 Reference(management.APIServiceGVK(), "my-rd-pods"), 58 `metadata.references.name==my-rd-pods;metadata.references.kind==APIService`, 59 }, 60 { 61 "by reference or attribute", 62 Or(AttrIn("a", "v1", "v2"), Reference(management.APIServiceGVK(), "my-rd-svc")), 63 `(attributes.a=in=("v1","v2"),metadata.references.name==my-rd-svc;metadata.references.kind==APIService)`, 64 }, 65 } 66 67 for i := range testCases { 68 tc := testCases[i] 69 t.Run(tc.name, func(t *testing.T) { 70 rv := newRSQLVisitor() 71 tc.input.Accept(rv) 72 if rv.String() != tc.expected { 73 t.Errorf("got: %s, expected: %s", rv.String(), tc.expected) 74 } 75 }) 76 } 77 }