summaryrefslogtreecommitdiff
path: root/pkg/util/filters_test.go
diff options
context:
space:
mode:
authorJakub Guzik <jakubmguzik@gmail.com>2021-03-23 00:13:44 +0100
committerJakub Guzik <jakubmguzik@gmail.com>2021-03-24 00:40:30 +0100
commit5eab1b07428e4078bd15ca5b69f28f2733850cdd (patch)
treeacc9b0a1f3b726cc117170bbca5ce60e27aa9083 /pkg/util/filters_test.go
parent4d3e71ad28f75b51dc5fa7a29775ce30c9d5c437 (diff)
downloadpodman-5eab1b07428e4078bd15ca5b69f28f2733850cdd.tar.gz
podman-5eab1b07428e4078bd15ca5b69f28f2733850cdd.tar.bz2
podman-5eab1b07428e4078bd15ca5b69f28f2733850cdd.zip
Unification of label filter across list/prune endpoints
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
Diffstat (limited to 'pkg/util/filters_test.go')
-rw-r--r--pkg/util/filters_test.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/pkg/util/filters_test.go b/pkg/util/filters_test.go
new file mode 100644
index 000000000..4771f682b
--- /dev/null
+++ b/pkg/util/filters_test.go
@@ -0,0 +1,77 @@
+package util
+
+import "testing"
+
+func TestMatchLabelFilters(t *testing.T) {
+ testLabels := map[string]string{
+ "label1": "",
+ "label2": "test",
+ "label3": "",
+ }
+ type args struct {
+ filterValues []string
+ labels map[string]string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "Match when all filters the same as labels",
+ args: args{
+ filterValues: []string{"label1", "label3", "label2=test"},
+ labels: testLabels,
+ },
+ want: true,
+ },
+ {
+ name: "Match when filter value not provided in args",
+ args: args{
+ filterValues: []string{"label2"},
+ labels: testLabels,
+ },
+ want: true,
+ },
+ {
+ name: "Match when no filter value is given",
+ args: args{
+ filterValues: []string{"label2="},
+ labels: testLabels,
+ },
+ want: true,
+ },
+ {
+ name: "Do not match when filter value differs",
+ args: args{
+ filterValues: []string{"label2=differs"},
+ labels: testLabels,
+ },
+ want: false,
+ },
+ {
+ name: "Do not match when filter value not listed in labels",
+ args: args{
+ filterValues: []string{"label1=xyz"},
+ labels: testLabels,
+ },
+ want: false,
+ },
+ {
+ name: "Do not match when one from many not ok",
+ args: args{
+ filterValues: []string{"label1=xyz", "invalid=valid"},
+ labels: testLabels,
+ },
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ tt := tt
+ t.Run(tt.name, func(t *testing.T) {
+ if got := MatchLabelFilters(tt.args.filterValues, tt.args.labels); got != tt.want {
+ t.Errorf("MatchLabelFilters() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}