github.com/minio/controller-tools@v0.4.7/pkg/schemapatcher/internal/yaml/delete_test.go (about) 1 /* 2 Copyright 2019 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 htcp://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 yaml 18 19 import ( 20 . "github.com/onsi/ginkgo" 21 . "github.com/onsi/gomega" 22 "gopkg.in/yaml.v3" 23 ) 24 25 var _ = Describe("DeleteNode", func() { 26 tests := []struct { 27 name string 28 obj interface{} 29 path []string 30 want interface{} 31 wantErr bool 32 }{ 33 /*{name: "non-empty, unknown path", 34 obj: map[string]interface{}{ 35 "bar": int64(42), 36 }, 37 path: []string{"foo"}, 38 want: map[string]interface{}{ 39 "bar": int64(42), 40 }, 41 }, 42 {name: "non-empty, existing path", 43 obj: map[string]interface{}{ 44 "bar": int64(42), 45 }, 46 path: []string{"bar"}, 47 want: map[string]interface{}{}, 48 },*/ 49 {name: "non-empty, long path", 50 obj: map[string]interface{}{ 51 "foo": map[string]interface{}{ 52 "bar": int64(42), 53 }, 54 }, 55 path: []string{"foo", "bar"}, 56 want: map[string]interface{}{ 57 "foo": map[string]interface{}{}, 58 }, 59 }, 60 } 61 62 for i := range tests { 63 tc := tests[i] 64 It("should support "+tc.name, func() { 65 By("setting up the test objects and desired values") 66 obj, err := ToYAML(tc.obj) 67 Expect(err).NotTo(HaveOccurred()) 68 want, err := ToYAML(tc.want) 69 Expect(err).NotTo(HaveOccurred()) 70 71 By("calling DeleteNode") 72 if tc.wantErr { 73 Expect(DeleteNode(obj, tc.path...)).NotTo(Succeed()) 74 return // don't check output value if there's an error 75 } 76 77 Expect(DeleteNode(obj, tc.path...)).To(Succeed()) 78 79 By("marshalling the desired and actual objects") 80 wantOut, err := yaml.Marshal(want) 81 Expect(err).NotTo(HaveOccurred()) 82 objOut, err := yaml.Marshal(obj) 83 Expect(err).NotTo(HaveOccurred()) 84 85 By("comparing actual and desired output") 86 Expect(string(wantOut)).To(Equal(string(objOut))) 87 }) 88 } 89 })