|
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 | )
|
@@ -67,85 +69,29 @@ func TestShouldShow(t *testing.T) {
|
67 | 69 | },
|
68 | 70 | }
|
69 | 71 |
|
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) { |
| 72 | + if !list.shouldShow([]string{"ipv4=10.29.85.0/24"}, inst, state) { |
123 | 73 | t.Errorf("net=10.29.85.0/24 filter didn't work")
|
124 | 74 | }
|
125 | 75 |
|
126 |
| - if list.shouldShow([]string{"ipv4=10.29.85.0/32"}, inst, state, false) { |
| 76 | + if list.shouldShow([]string{"ipv4=10.29.85.0/32"}, inst, state) { |
127 | 77 | t.Errorf("net=10.29.85.0/32 filter did work but should not")
|
128 | 78 | }
|
129 | 79 |
|
130 |
| - if !list.shouldShow([]string{"ipv4=10.29.85.156"}, inst, state, false) { |
| 80 | + if !list.shouldShow([]string{"ipv4=10.29.85.156"}, inst, state) { |
131 | 81 | t.Errorf("net=10.29.85.156 filter did not work")
|
132 | 82 | }
|
133 | 83 |
|
134 |
| - if !list.shouldShow([]string{"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:8301"}, inst, state, false) { |
| 84 | + if !list.shouldShow([]string{"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:8301"}, inst, state) { |
135 | 85 | t.Errorf("net=fd42:72a:89ac:e457:1266:6aff:fe83:8301 filter didn't work")
|
136 | 86 | }
|
137 | 87 |
|
138 |
| - if list.shouldShow([]string{"ipv6=fd42:072a:89ac:e457:1266:6aff:fe83:ffff/128"}, inst, state, false) { |
| 88 | + if list.shouldShow([]string{"ipv6=fd42:072a:89ac:e457:1266:6aff:fe83:ffff/128"}, inst, state) { |
139 | 89 | t.Errorf("net=1net=fd42:072a:89ac:e457:1266:6aff:fe83:ffff/128 filter did work but should not")
|
140 | 90 | }
|
141 | 91 |
|
142 |
| - if !list.shouldShow([]string{"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:ffff/1"}, inst, state, false) { |
| 92 | + if !list.shouldShow([]string{"ipv6=fd42:72a:89ac:e457:1266:6aff:fe83:ffff/1"}, inst, state) { |
143 | 93 | t.Errorf("net=fd42:72a:89ac:e457:1266:6aff:fe83:ffff/1 filter filter didn't work")
|
144 | 94 | }
|
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 | 95 | }
|
150 | 96 |
|
151 | 97 | // Used by TestColumns and TestInvalidColumns.
|
@@ -340,3 +286,10 @@ func TestInvalidColumns(t *testing.T) {
|
340 | 286 | run("config:image")
|
341 | 287 | run("devices:eth0")
|
342 | 288 | }
|
| 289 | + |
| 290 | +func TestPrepareInstanceServerFilters(t *testing.T) { |
| 291 | + filters := []string{"foo", "user.a=blah", "name=v1", "state=running"} |
| 292 | + |
| 293 | + result := prepareInstanceServerFilters(filters, api.InstanceFull{}) |
| 294 | + assert.Equal(t, []string{"name=(^foo$|^foo.*)", "expanded_config.user.a=blah", "name=v1", "status=running"}, result) |
| 295 | +} |
0 commit comments