github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/fields/fields_test.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package fields 18 19 import ( 20 "testing" 21 ) 22 23 func matches(t *testing.T, ls Set, want string) { 24 if ls.String() != want { 25 t.Errorf("Expected '%s', but got '%s'", want, ls.String()) 26 } 27 } 28 29 func TestSetString(t *testing.T) { 30 matches(t, Set{"x": "y"}, "x=y") 31 matches(t, Set{"foo": "bar"}, "foo=bar") 32 matches(t, Set{"foo": "bar", "baz": "qup"}, "baz=qup,foo=bar") 33 } 34 35 func TestFieldHas(t *testing.T) { 36 fieldHasTests := []struct { 37 Ls Fields 38 Key string 39 Has bool 40 }{ 41 {Set{"x": "y"}, "x", true}, 42 {Set{"x": ""}, "x", true}, 43 {Set{"x": "y"}, "foo", false}, 44 } 45 for _, lh := range fieldHasTests { 46 if has := lh.Ls.Has(lh.Key); has != lh.Has { 47 t.Errorf("%#v.Has(%#v) => %v, expected %v", lh.Ls, lh.Key, has, lh.Has) 48 } 49 } 50 } 51 52 func TestFieldGet(t *testing.T) { 53 ls := Set{"x": "y"} 54 if ls.Get("x") != "y" { 55 t.Errorf("Set.Get is broken") 56 } 57 }