github.com/OpsMx/go-app-base@v0.0.24/util/util_test.go (about) 1 // Copyright 2022 OpsMx, Inc 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package util 16 17 import "testing" 18 19 func TestContains(t *testing.T) { 20 type args struct { 21 elems []string 22 v string 23 } 24 tests := []struct { 25 name string 26 args args 27 want bool 28 }{ 29 { 30 "Empty list, blank target", 31 args{ 32 elems: []string{}, 33 v: "", 34 }, 35 false, 36 }, { 37 "Empty list, non-blank target", 38 args{ 39 elems: []string{}, 40 v: "foo", 41 }, 42 false, 43 }, { 44 "blank target", 45 args{ 46 elems: []string{"foo", "bar"}, 47 v: "", 48 }, 49 false, 50 }, { 51 "not present", 52 args{ 53 elems: []string{"foo", "bar"}, 54 v: "baz", 55 }, 56 false, 57 }, { 58 "present", 59 args{ 60 elems: []string{"foo", "bar"}, 61 v: "foo", 62 }, 63 true, 64 }, 65 } 66 for _, tt := range tests { 67 t.Run(tt.name, func(t *testing.T) { 68 if got := Contains(tt.args.elems, tt.args.v); got != tt.want { 69 t.Errorf("Contains() = %v, want %v", got, tt.want) 70 } 71 }) 72 } 73 }