github.com/sri09kanth/helm@v3.0.0-beta.3+incompatible/pkg/kube/resource_test.go (about) 1 /* 2 Copyright The Helm 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 kube // import "helm.sh/helm/pkg/kube" 18 19 import ( 20 "testing" 21 22 "k8s.io/apimachinery/pkg/api/meta" 23 "k8s.io/apimachinery/pkg/runtime/schema" 24 "k8s.io/cli-runtime/pkg/resource" 25 ) 26 27 func TestResourceList(t *testing.T) { 28 mapping := &meta.RESTMapping{ 29 Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "pod"}, 30 } 31 32 info := func(name string) *resource.Info { 33 return &resource.Info{Name: name, Mapping: mapping} 34 } 35 36 var r1, r2 ResourceList 37 r1 = []*resource.Info{info("foo"), info("bar")} 38 r2 = []*resource.Info{info("bar")} 39 40 diff := r1.Difference(r2) 41 if len(diff) != 1 { 42 t.Error("expected 1 result") 43 } 44 45 if !diff.Contains(info("foo")) { 46 t.Error("expected diff to return foo") 47 } 48 49 inter := r1.Intersect(r2) 50 if len(inter) != 1 { 51 t.Error("expected 1 result") 52 } 53 54 if !inter.Contains(info("bar")) { 55 t.Error("expected intersect to return bar") 56 } 57 }