...
1
16
17 package 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 }
62
View as plain text