This repository was archived by the owner on Feb 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathexpr_test.go
More file actions
64 lines (50 loc) · 1.73 KB
/
expr_test.go
File metadata and controls
64 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package filter
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseExprs(t *testing.T) {
// Cannot use the leading digit for key
_, err := parseExprs("constraint", []string{"constraint:1node"})
assert.Error(t, err)
// Cannot use space in key
_, err = parseExprs("constraint", []string{"constraint:node ==node1"})
assert.Error(t, err)
// Cannot use * in key
_, err = parseExprs("constraint", []string{"constraint:no*de==node1"})
assert.Error(t, err)
// Allow dot in key
_, err = parseExprs("constraint", []string{"constraint:no.de==node1"})
assert.NoError(t, err)
// Allow leading underscore
_, err = parseExprs("constraint", []string{"constraint:_node==_node1"})
assert.NoError(t, err)
// Allow globbing
_, err = parseExprs("constraint", []string{"constraint:node==*node*"})
assert.NoError(t, err)
// Allow regexp in value
_, err = parseExprs("constraint", []string{"constraint:node==/(?i)^[a-b]+c*(n|b)$/"})
assert.NoError(t, err)
// Allow space in value
_, err = parseExprs("constraint", []string{"constraint:node==node 1"})
assert.NoError(t, err)
}
func TestMatch(t *testing.T) {
e := expr{operator: EQ, value: "foo"}
assert.True(t, e.Match("foo"))
assert.False(t, e.Match("bar"))
assert.True(t, e.Match("foo", "bar"))
e = expr{operator: NOTEQ, value: "foo"}
assert.False(t, e.Match("foo"))
assert.True(t, e.Match("bar"))
assert.False(t, e.Match("foo", "bar"))
assert.False(t, e.Match("bar", "foo"))
e = expr{operator: EQ, value: "f*o"}
assert.True(t, e.Match("foo"))
assert.True(t, e.Match("fuo"))
assert.True(t, e.Match("foo", "fuo", "bar"))
e = expr{operator: NOTEQ, value: "f*o"}
assert.False(t, e.Match("foo"))
assert.False(t, e.Match("fuo"))
assert.False(t, e.Match("foo", "fuo", "bar"))
}