github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/domain/utils/utils_test.go (about) 1 package utils 2 3 import ( 4 "net/url" 5 "sort" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestToLibpodFilters(t *testing.T) { 12 good := url.Values{} 13 good.Set("apple", "red") 14 good.Set("banana", "yellow") 15 good.Set("pear", "") 16 goodResult := []string{"apple=red", "banana=yellow", "pear="} 17 sort.Strings(goodResult) 18 19 empty := url.Values{} 20 type args struct { 21 f url.Values 22 } 23 tests := []struct { 24 name string 25 args args 26 wantFilters []string 27 }{ 28 { 29 name: "GoodURLValue", 30 args: args{ 31 f: good, 32 }, 33 wantFilters: goodResult, 34 }, 35 { 36 name: "Empty", 37 args: args{ 38 f: empty, 39 }, 40 wantFilters: nil, 41 }, 42 } 43 for _, tt := range tests { 44 t.Run(tt.name, func(t *testing.T) { 45 assert.ElementsMatchf(t, ToLibpodFilters(tt.args.f), tt.wantFilters, "ToLibpodFilters() = %v, want %v", ToLibpodFilters(tt.args.f), tt.wantFilters) 46 }) 47 } 48 } 49 50 func TestToURLValues(t *testing.T) { 51 good := url.Values{} 52 good.Set("apple", "red") 53 good.Set("banana", "yellow") 54 good.Set("pear", "") 55 goodResult := []string{"apple=red", "banana=yellow", "pear="} 56 57 type args struct { 58 f []string 59 } 60 tests := []struct { 61 name string 62 args args 63 wantFilters url.Values 64 }{ 65 { 66 name: "Good", 67 args: args{goodResult}, 68 wantFilters: good, 69 }, 70 } 71 for _, tt := range tests { 72 t.Run(tt.name, func(t *testing.T) { 73 assert.EqualValuesf(t, ToURLValues(tt.args.f), tt.wantFilters, "ToURLValues() = %v, want %v", ToURLValues(tt.args.f), tt.wantFilters) 74 }) 75 } 76 }