Update status check endpoint 
[multicloud/k8s.git] / src / k8splugin / internal / statuscheck / resource_test.go
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 statuscheck // import "helm.sh/helm/v3/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         if r1.Get(info("bar")).Mapping.Resource.Resource != "pod" {
41                 t.Error("expected get pod")
42         }
43
44         diff := r1.Difference(r2)
45         if len(diff) != 1 {
46                 t.Error("expected 1 result")
47         }
48
49         if !diff.Contains(info("foo")) {
50                 t.Error("expected diff to return foo")
51         }
52
53         inter := r1.Intersect(r2)
54         if len(inter) != 1 {
55                 t.Error("expected 1 result")
56         }
57
58         if !inter.Contains(info("bar")) {
59                 t.Error("expected intersect to return bar")
60         }
61 }