diff options
author | Brent Baude <bbaude@redhat.com> | 2022-05-03 09:23:43 -0500 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2022-05-05 15:48:26 -0400 |
commit | b2025c64f43e74c84fb928f07df7bab3f776fe2d (patch) | |
tree | 9a82391677b38691363d905d14de6317853d9f0e /pkg/domain/utils | |
parent | 7b64cd7835f1bacd326096fc5e41d44957a79230 (diff) | |
download | podman-b2025c64f43e74c84fb928f07df7bab3f776fe2d.tar.gz podman-b2025c64f43e74c84fb928f07df7bab3f776fe2d.tar.bz2 podman-b2025c64f43e74c84fb928f07df7bab3f776fe2d.zip |
Add more unit tests
Improve "code coverage" with more unit-tests.
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/domain/utils')
-rw-r--r-- | pkg/domain/utils/utils_test.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/pkg/domain/utils/utils_test.go b/pkg/domain/utils/utils_test.go new file mode 100644 index 000000000..952a4b5be --- /dev/null +++ b/pkg/domain/utils/utils_test.go @@ -0,0 +1,76 @@ +package utils + +import ( + "net/url" + "sort" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestToLibpodFilters(t *testing.T) { + good := url.Values{} + good.Set("apple", "red") + good.Set("banana", "yellow") + good.Set("pear", "") + goodResult := []string{"apple=red", "banana=yellow", "pear="} + sort.Strings(goodResult) + + empty := url.Values{} + type args struct { + f url.Values + } + tests := []struct { + name string + args args + wantFilters []string + }{ + { + name: "GoodURLValue", + args: args{ + f: good, + }, + wantFilters: goodResult, + }, + { + name: "Empty", + args: args{ + f: empty, + }, + wantFilters: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.ElementsMatchf(t, ToLibpodFilters(tt.args.f), tt.wantFilters, "ToLibpodFilters() = %v, want %v", ToLibpodFilters(tt.args.f), tt.wantFilters) + }) + } +} + +func TestToURLValues(t *testing.T) { + good := url.Values{} + good.Set("apple", "red") + good.Set("banana", "yellow") + good.Set("pear", "") + goodResult := []string{"apple=red", "banana=yellow", "pear="} + + type args struct { + f []string + } + tests := []struct { + name string + args args + wantFilters url.Values + }{ + { + name: "Good", + args: args{goodResult}, + wantFilters: good, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.EqualValuesf(t, ToURLValues(tt.args.f), tt.wantFilters, "ToURLValues() = %v, want %v", ToURLValues(tt.args.f), tt.wantFilters) + }) + } +} |