From 402996e262541ed25521145fa750e723cad4dfb1 Mon Sep 17 00:00:00 2001 From: WillSmisi <764947976@11.com> Date: Sat, 22 Dec 2018 11:27:54 +0800 Subject: [PATCH] test: add test cases for parse_test.go --- apis/filters/parse_test.go | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/apis/filters/parse_test.go b/apis/filters/parse_test.go index c7b7e89a38..f60ffa763f 100644 --- a/apis/filters/parse_test.go +++ b/apis/filters/parse_test.go @@ -223,3 +223,54 @@ func TestArgsMatchKVList(t *testing.T) { } } } + +func TestArgsValidate(t *testing.T) { + tests := []struct { + name string + testArgs Args + accepted map[string]bool + wantErr bool + }{ + { + "mapping keys are in the accepted set", + Args{ + map[string]map[string]bool{ + "created": { + "today": true, + }, + }, + }, + + map[string]bool{ + "created": true, + }, + + false, + }, + { + "mapping keys are not in the accepted set", + Args{ + map[string]map[string]bool{ + "created": { + "today": true, + }, + }, + }, + + map[string]bool{ + "created": false, + }, + + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.testArgs.Validate(tt.accepted) + if (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + return + } + }) + } +}