| 
									
										
										
										
											2017-01-14 04:41:21 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2018-08-25 03:03:55 +08:00
										 |  |  | Copyright The Helm Authors. | 
					
						
							| 
									
										
										
										
											2017-01-14 04:41:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  | you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | You may obtain a copy of the License at | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  | distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | See the License for the specific language governing permissions and | 
					
						
							|  |  |  | limitations under the License. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 02:27:05 +08:00
										 |  |  | package kube // import "helm.sh/helm/v3/pkg/kube"
 | 
					
						
							| 
									
										
										
										
											2017-01-14 04:41:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 00:51:19 +08:00
										 |  |  | 	"k8s.io/apimachinery/pkg/api/meta" | 
					
						
							| 
									
										
										
										
											2017-04-11 13:47:10 +08:00
										 |  |  | 	"k8s.io/apimachinery/pkg/runtime/schema" | 
					
						
							| 
									
										
										
										
											2019-03-26 05:01:01 +08:00
										 |  |  | 	"k8s.io/cli-runtime/pkg/resource" | 
					
						
							| 
									
										
										
										
											2017-01-14 04:41:21 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-24 06:11:31 +08:00
										 |  |  | func TestResourceList(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-08-23 00:51:19 +08:00
										 |  |  | 	mapping := &meta.RESTMapping{ | 
					
						
							|  |  |  | 		Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "pod"}, | 
					
						
							| 
									
										
										
										
											2017-01-14 04:41:21 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	info := func(name string) *resource.Info { | 
					
						
							|  |  |  | 		return &resource.Info{Name: name, Mapping: mapping} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-24 06:11:31 +08:00
										 |  |  | 	var r1, r2 ResourceList | 
					
						
							| 
									
										
										
										
											2017-01-14 04:41:21 +08:00
										 |  |  | 	r1 = []*resource.Info{info("foo"), info("bar")} | 
					
						
							|  |  |  | 	r2 = []*resource.Info{info("bar")} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-23 20:53:10 +08:00
										 |  |  | 	if r1.Get(info("bar")).Mapping.Resource.Resource != "pod" { | 
					
						
							|  |  |  | 		t.Error("expected get pod") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 04:41:21 +08:00
										 |  |  | 	diff := r1.Difference(r2) | 
					
						
							|  |  |  | 	if len(diff) != 1 { | 
					
						
							|  |  |  | 		t.Error("expected 1 result") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !diff.Contains(info("foo")) { | 
					
						
							|  |  |  | 		t.Error("expected diff to return foo") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	inter := r1.Intersect(r2) | 
					
						
							|  |  |  | 	if len(inter) != 1 { | 
					
						
							|  |  |  | 		t.Error("expected 1 result") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !inter.Contains(info("bar")) { | 
					
						
							|  |  |  | 		t.Error("expected intersect to return bar") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |