@@ -7,22 +7,12 @@ import (
7
7
"strings"
8
8
"testing"
9
9
10
+ "github.com/stretchr/testify/assert"
11
+
10
12
"github.com/lxc/incus/v6/internal/instance"
11
13
"github.com/lxc/incus/v6/shared/api"
12
14
)
13
15
14
- func TestDotPrefixMatch (t * testing.T ) {
15
- list := cmdList {}
16
-
17
- pass := true
18
- pass = pass && list .dotPrefixMatch ("s.privileged" , "security.privileged" )
19
- pass = pass && list .dotPrefixMatch ("u.blah" , "user.blah" )
20
-
21
- if ! pass {
22
- t .Error ("failed prefix matching" )
23
- }
24
- }
25
-
26
16
func TestShouldShow (t * testing.T ) {
27
17
list := cmdList {}
28
18
inst := & api.Instance {
@@ -67,85 +57,29 @@ func TestShouldShow(t *testing.T) {
67
57
},
68
58
}
69
59
70
- if ! list .shouldShow ([]string {"u.blah=abc" }, inst , nil , false ) {
71
- t .Error ("u.blah=abc didn't match" )
72
- }
73
-
74
- if ! list .shouldShow ([]string {"user.blah=abc" }, inst , nil , false ) {
75
- t .Error ("user.blah=abc didn't match" )
76
- }
77
-
78
- if ! list .shouldShow ([]string {"status=RUNNING" , "user.blah=abc" }, inst , nil , false ) {
79
- t .Error ("user.blah=abc status=RUNNING didn't match" )
80
- }
81
-
82
- if ! list .shouldShow ([]string {"image.os=Debian" , "user.blah=abc" }, inst , nil , false ) {
83
- t .Error ("user.blah=abc os=debian didn't match" )
84
- }
85
-
86
- if ! list .shouldShow ([]string {"location=mem-brain" , "user.blah=abc" }, inst , nil , false ) {
87
- t .Error ("user.blah=abc location=mem-brain didn't match" )
88
- }
89
-
90
- if ! list .shouldShow ([]string {"architecture=potato" , "user.blah=abc" }, inst , nil , false ) {
91
- t .Error ("user.blah=abc architecture=potato didn't match" )
92
- }
93
-
94
- if ! list .shouldShow ([]string {"foo" , "user.blah=abc" }, inst , nil , false ) {
95
- t .Error ("user.blah=abc foo didn't match" )
96
- }
97
-
98
- if list .shouldShow ([]string {"image.os=temple-os" , "user.blah=abc" }, inst , nil , false ) {
99
- t .Error ("user.blah=abc image.os=temple-os did match" )
100
- }
101
-
102
- if list .shouldShow ([]string {"status=RUNNING" , "type=virtual-machine" , "user.blah=abc" }, inst , nil , false ) {
103
- t .Error ("user.blah=abc status=RUNNING, type=virtual-machine did match " )
104
- }
105
-
106
- if list .shouldShow ([]string {"status=FROZEN,STOPPED" }, inst , nil , false ) {
107
- t .Error ("status=FROZEN,STOPPED did not match " )
108
- }
109
-
110
- if ! list .shouldShow ([]string {"status=RUNNING,STOPPED" }, inst , nil , false ) {
111
- t .Error ("status=RUNNING,STOPPED did not match " )
112
- }
113
-
114
- if ! list .shouldShow ([]string {"type=container" , "user.blah=abc" }, inst , nil , false ) {
115
- t .Error ("user.blah=abc type=container didn't match" )
116
- }
117
-
118
- if list .shouldShow ([]string {"bar" , "u.blah=other" }, inst , nil , false ) {
119
- t .Errorf ("value filter didn't work" )
120
- }
121
-
122
- if ! list .shouldShow ([]string {"ipv4=10.29.85.0/24" }, inst , state , false ) {
60
+ if ! list .shouldShow ([]string {"ipv4=10.29.85.0/24" }, inst , state ) {
123
61
t .Errorf ("net=10.29.85.0/24 filter didn't work" )
124
62
}
125
63
126
- if list .shouldShow ([]string {"ipv4=10.29.85.0/32" }, inst , state , false ) {
64
+ if list .shouldShow ([]string {"ipv4=10.29.85.0/32" }, inst , state ) {
127
65
t .Errorf ("net=10.29.85.0/32 filter did work but should not" )
128
66
}
129
67
130
- if ! list .shouldShow ([]string {"ipv4=10.29.85.156" }, inst , state , false ) {
68
+ if ! list .shouldShow ([]string {"ipv4=10.29.85.156" }, inst , state ) {
131
69
t .Errorf ("net=10.29.85.156 filter did not work" )
132
70
}
133
71
134
- if ! list .shouldShow ([]string {"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:8301" }, inst , state , false ) {
72
+ if ! list .shouldShow ([]string {"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:8301" }, inst , state ) {
135
73
t .Errorf ("net=fd42:72a:89ac:e457:1266:6aff:fe83:8301 filter didn't work" )
136
74
}
137
75
138
- if list .shouldShow ([]string {"ipv6=fd42:072a:89ac:e457:1266:6aff:fe83:ffff/128" }, inst , state , false ) {
76
+ if list .shouldShow ([]string {"ipv6=fd42:072a:89ac:e457:1266:6aff:fe83:ffff/128" }, inst , state ) {
139
77
t .Errorf ("net=1net=fd42:072a:89ac:e457:1266:6aff:fe83:ffff/128 filter did work but should not" )
140
78
}
141
79
142
- if ! list .shouldShow ([]string {"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:ffff/1" }, inst , state , false ) {
80
+ if ! list .shouldShow ([]string {"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:ffff/1" }, inst , state ) {
143
81
t .Errorf ("net=fd42:72a:89ac:e457:1266:6aff:fe83:ffff/1 filter filter didn't work" )
144
82
}
145
-
146
- if list .shouldShow ([]string {"user.blah=abc" , "status=stopped" }, inst , nil , false ) {
147
- t .Error ("user.blah=abc status=stopped did match even though container status is 'running'" )
148
- }
149
83
}
150
84
151
85
// Used by TestColumns and TestInvalidColumns.
@@ -340,3 +274,10 @@ func TestInvalidColumns(t *testing.T) {
340
274
run ("config:image" )
341
275
run ("devices:eth0" )
342
276
}
277
+
278
+ func TestPrepareInstanceServerFilters (t * testing.T ) {
279
+ filters := []string {"foo" , "user.a=blah" , "name=v1" , "state=running" }
280
+
281
+ result := prepareInstanceServerFilters (filters , api.InstanceFull {})
282
+ assert .Equal (t , []string {"name=(^foo$|^foo.*)" , "expanded_config.user.a=blah" , "name=v1" , "status=running" }, result )
283
+ }
0 commit comments