NewSimpleClientset returns a clientset that will respond with the provided objects. It's backed by a very simple object tracker that processes creates, updates and deletions as-is, without applying any validations and/or defaults. It shouldn't be considered a replacement for a real clientset and is
(objects ...runtime.Object)
| 104 | // without applying any validations and/or defaults. It shouldn't be considered a replacement |
| 105 | // for a real clientset and is mostly useful in simple unit tests. |
| 106 | func NewSimpleClientset(objects ...runtime.Object) *Clientset { |
| 107 | o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) |
| 108 | for _, obj := range objects { |
| 109 | if err := o.Add(obj); err != nil { |
| 110 | panic(err) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | cs := &Clientset{tracker: o} |
| 115 | cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} |
| 116 | cs.AddReactor("*", "*", testing.ObjectReaction(o)) |
| 117 | cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { |
| 118 | gvr := action.GetResource() |
| 119 | ns := action.GetNamespace() |
| 120 | watch, err := o.Watch(gvr, ns) |
| 121 | if err != nil { |
| 122 | return false, nil, err |
| 123 | } |
| 124 | return true, watch, nil |
| 125 | }) |
| 126 | |
| 127 | return cs |
| 128 | } |
| 129 | |
| 130 | // Clientset implements clientset.Interface. Meant to be embedded into a |
| 131 | // struct to get a default implementation. This makes faking out just the method |