github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/verrazzano-backup-hook/utilities/vzk8sfake/spdy.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package vzk8sfake 5 6 import ( 7 "bytes" 8 "k8s.io/client-go/rest" 9 "k8s.io/client-go/tools/remotecommand" 10 "net/url" 11 ) 12 13 // PodSTDOUT can be used to output arbitrary strings during unit testing 14 var PodSTDOUT = "" 15 16 // NewPodExecutor should be used instead of remotecommand.NewSPDYExecutor in unit tests 17 func NewPodExecutor(config *rest.Config, method string, url *url.URL) (remotecommand.Executor, error) { 18 return &dummyExecutor{method: method, url: url}, nil 19 } 20 21 // dummyExecutor is for unit testing 22 type dummyExecutor struct { 23 method string 24 url *url.URL 25 } 26 27 // Stream on a dummyExecutor sets stdout to PodSTDOUT 28 func (f *dummyExecutor) Stream(options remotecommand.StreamOptions) error { 29 if options.Stdout != nil { 30 buf := new(bytes.Buffer) 31 buf.WriteString(PodSTDOUT) 32 if _, err := options.Stdout.Write(buf.Bytes()); err != nil { 33 return err 34 } 35 } 36 return nil 37 }