Michael Dresser 3 лет назад
Родитель
Сommit
2bbab58ca4

+ 15 - 0
pkg/util/allocationfilterutil/v2/lexer_test.go

@@ -75,6 +75,21 @@ func TestLexer(t *testing.T) {
 				{kind: eof},
 			},
 		},
+		{
+			name:  "whitespace separated accesses",
+			input: `node : "abc" , "def" ` + string('\r') + string('\n') + string('\t') + `namespace : "123"`,
+			expected: []token{
+				{kind: filterField1, s: "node"},
+				{kind: colon, s: ":"},
+				{kind: str, s: "abc"},
+				{kind: comma, s: ","},
+				{kind: str, s: "def"},
+				{kind: filterField1, s: "namespace"},
+				{kind: colon, s: ":"},
+				{kind: str, s: "123"},
+				{kind: eof},
+			},
+		},
 	}
 
 	for _, c := range cases {

+ 24 - 0
pkg/util/allocationfilterutil/v2/parser_test.go

@@ -91,6 +91,30 @@ func TestParse(t *testing.T) {
 				allocGenerator(kubecost.AllocationProperties{Namespace: "abc"}),
 			},
 		},
+		{
+			input: `node:"node a b c" , "node 12 3"` + string('\n') + "+" + string('\n') + string('\r') + `namespace : "kubecost"`,
+			expected: kubecost.AllocationFilterAnd{[]kubecost.AllocationFilter{
+				kubecost.AllocationFilterOr{[]kubecost.AllocationFilter{
+					kubecost.AllocationFilterCondition{
+						Field: kubecost.FilterNode,
+						Op:    kubecost.FilterEquals,
+						Value: "node a b c",
+					},
+					kubecost.AllocationFilterCondition{
+						Field: kubecost.FilterNode,
+						Op:    kubecost.FilterEquals,
+						Value: "node 12 3",
+					},
+				}},
+				kubecost.AllocationFilterOr{[]kubecost.AllocationFilter{
+					kubecost.AllocationFilterCondition{
+						Field: kubecost.FilterNamespace,
+						Op:    kubecost.FilterEquals,
+						Value: "kubecost",
+					},
+				}},
+			}},
+		},
 		{
 			input: `label[app_abc]:"cost_analyzer"`,
 			expected: kubecost.AllocationFilterAnd{[]kubecost.AllocationFilter{