github.com/azure-devops-engineer/helm@v3.0.0-alpha.2+incompatible/pkg/kube/fake/fake.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 fake implements various fake KubeClients for use in testing 18 package fake 19 20 import ( 21 "io" 22 "time" 23 24 v1 "k8s.io/api/core/v1" 25 "k8s.io/cli-runtime/pkg/resource" 26 27 "helm.sh/helm/pkg/kube" 28 ) 29 30 // FailingKubeClient implements KubeClient for testing purposes. It also has 31 // additional errors you can set to fail different functions, otherwise it 32 // delegates all its calls to `PrintingKubeClient` 33 type FailingKubeClient struct { 34 PrintingKubeClient 35 CreateError error 36 WaitError error 37 GetError error 38 DeleteError error 39 WatchUntilReadyError error 40 UpdateError error 41 BuildError error 42 BuildUnstructuredError error 43 WaitAndGetCompletedPodPhaseError error 44 } 45 46 // Create returns the configured error if set or prints 47 func (f *FailingKubeClient) Create(r io.Reader) error { 48 if f.CreateError != nil { 49 return f.CreateError 50 } 51 return f.PrintingKubeClient.Create(r) 52 } 53 54 // Wait returns the configured error if set or prints 55 func (f *FailingKubeClient) Wait(r io.Reader, d time.Duration) error { 56 if f.WaitError != nil { 57 return f.WaitError 58 } 59 return f.PrintingKubeClient.Wait(r, d) 60 } 61 62 // Create returns the configured error if set or prints 63 func (f *FailingKubeClient) Get(r io.Reader) (string, error) { 64 if f.GetError != nil { 65 return "", f.GetError 66 } 67 return f.PrintingKubeClient.Get(r) 68 } 69 70 // Delete returns the configured error if set or prints 71 func (f *FailingKubeClient) Delete(r io.Reader) error { 72 if f.DeleteError != nil { 73 return f.DeleteError 74 } 75 return f.PrintingKubeClient.Delete(r) 76 } 77 78 // WatchUntilReady returns the configured error if set or prints 79 func (f *FailingKubeClient) WatchUntilReady(r io.Reader, d time.Duration) error { 80 if f.WatchUntilReadyError != nil { 81 return f.WatchUntilReadyError 82 } 83 return f.PrintingKubeClient.WatchUntilReady(r, d) 84 } 85 86 // Update returns the configured error if set or prints 87 func (f *FailingKubeClient) Update(r, modifiedReader io.Reader, not, needed bool) error { 88 if f.UpdateError != nil { 89 return f.UpdateError 90 } 91 return f.PrintingKubeClient.Update(r, modifiedReader, not, needed) 92 } 93 94 // Build returns the configured error if set or prints 95 func (f *FailingKubeClient) Build(r io.Reader) (kube.Result, error) { 96 if f.BuildError != nil { 97 return []*resource.Info{}, f.BuildError 98 } 99 return f.PrintingKubeClient.Build(r) 100 } 101 102 // BuildUnstructured returns the configured error if set or prints 103 func (f *FailingKubeClient) BuildUnstructured(r io.Reader) (kube.Result, error) { 104 if f.BuildUnstructuredError != nil { 105 return []*resource.Info{}, f.BuildUnstructuredError 106 } 107 return f.PrintingKubeClient.Build(r) 108 } 109 110 // WaitAndGetCompletedPodPhase returns the configured error if set or prints 111 func (f *FailingKubeClient) WaitAndGetCompletedPodPhase(s string, d time.Duration) (v1.PodPhase, error) { 112 if f.WaitAndGetCompletedPodPhaseError != nil { 113 return v1.PodSucceeded, f.WaitAndGetCompletedPodPhaseError 114 } 115 return f.PrintingKubeClient.WaitAndGetCompletedPodPhase(s, d) 116 }