github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/api/apitesting/fuzzer/valuefuzz_test.go (about) 1 /* 2 Copyright 2017 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 fuzzer 18 19 import "testing" 20 21 func TestValueFuzz(t *testing.T) { 22 type ( 23 Y struct { 24 I int 25 B bool 26 F float32 27 U uint 28 } 29 X struct { 30 Ptr *X 31 Y Y 32 Map map[string]int 33 Slice []int 34 } 35 ) 36 37 x := X{ 38 Ptr: &X{}, 39 Map: map[string]int{"foo": 42}, 40 Slice: []int{1, 2, 3}, 41 } 42 43 p := x.Ptr 44 m := x.Map 45 s := x.Slice 46 47 ValueFuzz(x) 48 49 if x.Ptr.Y.I == 0 { 50 t.Errorf("x.Ptr.Y.I should have changed") 51 } 52 53 if x.Map["foo"] == 42 { 54 t.Errorf("x.Map[foo] should have changed") 55 } 56 57 if x.Slice[0] == 1 { 58 t.Errorf("x.Slice[0] should have changed") 59 } 60 61 if x.Ptr != p { 62 t.Errorf("x.Ptr changed") 63 } 64 65 m["foo"] = 7 66 if x.Map["foo"] != m["foo"] { 67 t.Errorf("x.Map changed") 68 } 69 s[0] = 7 70 if x.Slice[0] != s[0] { 71 t.Errorf("x.Slice changed") 72 } 73 }