From 4b2d3124e967aa0fc68bd8c4db9d0ca67dc606cb Mon Sep 17 00:00:00 2001 From: jcvrabo <122891959+jcvrabo@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:26:46 +0100 Subject: [PATCH] merge cfnetworking updates from main --- actor/cfnetworkingaction/policy_test.go | 2 +- .../cfnetv1/cfnetv1_suite_test.go | 2 +- .../cfnetv1fakes/fake_connection_wrapper.go | 70 ++-- api/cfnetworking/cfnetv1/cfvnetv1.go | 3 + .../cfnetv1/connection_wrapper.go | 4 +- api/cfnetworking/cfnetv1/policy.go | 6 +- api/cfnetworking/cfnetv1/policy_test.go | 6 +- api/cfnetworking/cfnetworking.go | 6 + api/cfnetworking/cfnetworking_suite_test.go | 2 +- .../cfnetworkingfakes/fake_connection.go | 37 +- .../cfnetworkingfakes/fake_read_seeker.go | 78 ++-- api/cfnetworking/connection.go | 4 +- api/cfnetworking/errors_test.go | 3 +- .../networkerror/request_error.go | 2 +- .../networkerror/unverified_server_error.go | 2 +- api/cfnetworking/networking_connection.go | 21 +- .../networking_connection_test.go | 22 +- api/cfnetworking/request.go | 3 +- api/cfnetworking/wrapper/request_logger.go | 12 +- .../wrapper/request_logger_test.go | 6 +- .../wrapper/retry_request_test.go | 7 +- .../wrapper/uaa_authentication.go | 8 +- .../wrapper/uaa_authentication_test.go | 8 +- .../wrapper/util/in_memory_cache.go | 4 +- api/cfnetworking/wrapper/wrapper.go | 3 + .../wrapper/wrapper_suite_test.go | 5 +- .../fake_request_logger_output.go | 337 ++++++++++++------ .../wrapper/wrapperfakes/fake_token_cache.go | 104 ++++-- .../wrapper/wrapperfakes/fake_uaaclient.go | 33 +- command/v7/shared/new_clients_test.go | 4 +- 30 files changed, 531 insertions(+), 273 deletions(-) create mode 100644 api/cfnetworking/cfnetv1/cfvnetv1.go create mode 100644 api/cfnetworking/cfnetworking.go create mode 100644 api/cfnetworking/wrapper/wrapper.go diff --git a/actor/cfnetworkingaction/policy_test.go b/actor/cfnetworkingaction/policy_test.go index beaf6585ea1..925a605ae93 100644 --- a/actor/cfnetworkingaction/policy_test.go +++ b/actor/cfnetworkingaction/policy_test.go @@ -4,12 +4,12 @@ import ( "errors" "fmt" + "code.cloudfoundry.org/cli/v8/api/cfnetworking/cfnetv1" "code.cloudfoundry.org/cli/v8/api/cloudcontroller/ccv3" "code.cloudfoundry.org/cli/v8/api/cloudcontroller/ccv3/constant" "code.cloudfoundry.org/cli/v8/resources" "code.cloudfoundry.org/cli/v8/util/batcher" - "code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/cfnetv1" "code.cloudfoundry.org/cli/v8/actor/actionerror" . "code.cloudfoundry.org/cli/v8/actor/cfnetworkingaction" "code.cloudfoundry.org/cli/v8/actor/cfnetworkingaction/cfnetworkingactionfakes" diff --git a/api/cfnetworking/cfnetv1/cfnetv1_suite_test.go b/api/cfnetworking/cfnetv1/cfnetv1_suite_test.go index d5247f96686..abc09445426 100644 --- a/api/cfnetworking/cfnetv1/cfnetv1_suite_test.go +++ b/api/cfnetworking/cfnetv1/cfnetv1_suite_test.go @@ -7,7 +7,7 @@ import ( . "code.cloudfoundry.org/cli/v8/api/cfnetworking/cfnetv1" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" ) diff --git a/api/cfnetworking/cfnetv1/cfnetv1fakes/fake_connection_wrapper.go b/api/cfnetworking/cfnetv1/cfnetv1fakes/fake_connection_wrapper.go index ff54ed37aad..58444b2871f 100644 --- a/api/cfnetworking/cfnetv1/cfnetv1fakes/fake_connection_wrapper.go +++ b/api/cfnetworking/cfnetv1/cfnetv1fakes/fake_connection_wrapper.go @@ -9,11 +9,11 @@ import ( ) type FakeConnectionWrapper struct { - MakeStub func(request *cfnetworking.Request, passedResponse *cfnetworking.Response) error + MakeStub func(*cfnetworking.Request, *cfnetworking.Response) error makeMutex sync.RWMutex makeArgsForCall []struct { - request *cfnetworking.Request - passedResponse *cfnetworking.Response + arg1 *cfnetworking.Request + arg2 *cfnetworking.Response } makeReturns struct { result1 error @@ -21,10 +21,10 @@ type FakeConnectionWrapper struct { makeReturnsOnCall map[int]struct { result1 error } - WrapStub func(innerconnection cfnetworking.Connection) cfnetworking.Connection + WrapStub func(cfnetworking.Connection) cfnetworking.Connection wrapMutex sync.RWMutex wrapArgsForCall []struct { - innerconnection cfnetworking.Connection + arg1 cfnetworking.Connection } wrapReturns struct { result1 cfnetworking.Connection @@ -36,22 +36,24 @@ type FakeConnectionWrapper struct { invocationsMutex sync.RWMutex } -func (fake *FakeConnectionWrapper) Make(request *cfnetworking.Request, passedResponse *cfnetworking.Response) error { +func (fake *FakeConnectionWrapper) Make(arg1 *cfnetworking.Request, arg2 *cfnetworking.Response) error { fake.makeMutex.Lock() ret, specificReturn := fake.makeReturnsOnCall[len(fake.makeArgsForCall)] fake.makeArgsForCall = append(fake.makeArgsForCall, struct { - request *cfnetworking.Request - passedResponse *cfnetworking.Response - }{request, passedResponse}) - fake.recordInvocation("Make", []interface{}{request, passedResponse}) + arg1 *cfnetworking.Request + arg2 *cfnetworking.Response + }{arg1, arg2}) + stub := fake.MakeStub + fakeReturns := fake.makeReturns + fake.recordInvocation("Make", []interface{}{arg1, arg2}) fake.makeMutex.Unlock() - if fake.MakeStub != nil { - return fake.MakeStub(request, passedResponse) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - return fake.makeReturns.result1 + return fakeReturns.result1 } func (fake *FakeConnectionWrapper) MakeCallCount() int { @@ -60,13 +62,22 @@ func (fake *FakeConnectionWrapper) MakeCallCount() int { return len(fake.makeArgsForCall) } +func (fake *FakeConnectionWrapper) MakeCalls(stub func(*cfnetworking.Request, *cfnetworking.Response) error) { + fake.makeMutex.Lock() + defer fake.makeMutex.Unlock() + fake.MakeStub = stub +} + func (fake *FakeConnectionWrapper) MakeArgsForCall(i int) (*cfnetworking.Request, *cfnetworking.Response) { fake.makeMutex.RLock() defer fake.makeMutex.RUnlock() - return fake.makeArgsForCall[i].request, fake.makeArgsForCall[i].passedResponse + argsForCall := fake.makeArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeConnectionWrapper) MakeReturns(result1 error) { + fake.makeMutex.Lock() + defer fake.makeMutex.Unlock() fake.MakeStub = nil fake.makeReturns = struct { result1 error @@ -74,6 +85,8 @@ func (fake *FakeConnectionWrapper) MakeReturns(result1 error) { } func (fake *FakeConnectionWrapper) MakeReturnsOnCall(i int, result1 error) { + fake.makeMutex.Lock() + defer fake.makeMutex.Unlock() fake.MakeStub = nil if fake.makeReturnsOnCall == nil { fake.makeReturnsOnCall = make(map[int]struct { @@ -85,21 +98,23 @@ func (fake *FakeConnectionWrapper) MakeReturnsOnCall(i int, result1 error) { }{result1} } -func (fake *FakeConnectionWrapper) Wrap(innerconnection cfnetworking.Connection) cfnetworking.Connection { +func (fake *FakeConnectionWrapper) Wrap(arg1 cfnetworking.Connection) cfnetworking.Connection { fake.wrapMutex.Lock() ret, specificReturn := fake.wrapReturnsOnCall[len(fake.wrapArgsForCall)] fake.wrapArgsForCall = append(fake.wrapArgsForCall, struct { - innerconnection cfnetworking.Connection - }{innerconnection}) - fake.recordInvocation("Wrap", []interface{}{innerconnection}) + arg1 cfnetworking.Connection + }{arg1}) + stub := fake.WrapStub + fakeReturns := fake.wrapReturns + fake.recordInvocation("Wrap", []interface{}{arg1}) fake.wrapMutex.Unlock() - if fake.WrapStub != nil { - return fake.WrapStub(innerconnection) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1 } - return fake.wrapReturns.result1 + return fakeReturns.result1 } func (fake *FakeConnectionWrapper) WrapCallCount() int { @@ -108,13 +123,22 @@ func (fake *FakeConnectionWrapper) WrapCallCount() int { return len(fake.wrapArgsForCall) } +func (fake *FakeConnectionWrapper) WrapCalls(stub func(cfnetworking.Connection) cfnetworking.Connection) { + fake.wrapMutex.Lock() + defer fake.wrapMutex.Unlock() + fake.WrapStub = stub +} + func (fake *FakeConnectionWrapper) WrapArgsForCall(i int) cfnetworking.Connection { fake.wrapMutex.RLock() defer fake.wrapMutex.RUnlock() - return fake.wrapArgsForCall[i].innerconnection + argsForCall := fake.wrapArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeConnectionWrapper) WrapReturns(result1 cfnetworking.Connection) { + fake.wrapMutex.Lock() + defer fake.wrapMutex.Unlock() fake.WrapStub = nil fake.wrapReturns = struct { result1 cfnetworking.Connection @@ -122,6 +146,8 @@ func (fake *FakeConnectionWrapper) WrapReturns(result1 cfnetworking.Connection) } func (fake *FakeConnectionWrapper) WrapReturnsOnCall(i int, result1 cfnetworking.Connection) { + fake.wrapMutex.Lock() + defer fake.wrapMutex.Unlock() fake.WrapStub = nil if fake.wrapReturnsOnCall == nil { fake.wrapReturnsOnCall = make(map[int]struct { diff --git a/api/cfnetworking/cfnetv1/cfvnetv1.go b/api/cfnetworking/cfnetv1/cfvnetv1.go new file mode 100644 index 00000000000..c80661d5e30 --- /dev/null +++ b/api/cfnetworking/cfnetv1/cfvnetv1.go @@ -0,0 +1,3 @@ +package cfnetv1 + +//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate diff --git a/api/cfnetworking/cfnetv1/connection_wrapper.go b/api/cfnetworking/cfnetv1/connection_wrapper.go index 2207c4f9dbe..52cd4269430 100644 --- a/api/cfnetworking/cfnetv1/connection_wrapper.go +++ b/api/cfnetworking/cfnetv1/connection_wrapper.go @@ -2,10 +2,10 @@ package cfnetv1 import "code.cloudfoundry.org/cli/v8/api/cfnetworking" -//go:generate counterfeiter . ConnectionWrapper - // ConnectionWrapper can wrap a given connection allowing the wrapper to modify // all requests going in and out of the given connection. +// +//counterfeiter:generate . ConnectionWrapper type ConnectionWrapper interface { cfnetworking.Connection Wrap(innerconnection cfnetworking.Connection) cfnetworking.Connection diff --git a/api/cfnetworking/cfnetv1/policy.go b/api/cfnetworking/cfnetv1/policy.go index 28ba971561d..68589888ea2 100644 --- a/api/cfnetworking/cfnetv1/policy.go +++ b/api/cfnetworking/cfnetv1/policy.go @@ -37,7 +37,7 @@ type PolicyDestination struct { } // CreatePolicies will create the network policy with the given parameters. -func (client Client) CreatePolicies(policies []Policy) error { +func (client *Client) CreatePolicies(policies []Policy) error { rawJSON, err := json.Marshal(PolicyList{Policies: policies}) if err != nil { return err @@ -55,7 +55,7 @@ func (client Client) CreatePolicies(policies []Policy) error { } // ListPolicies will list the policies with the app guids in either the source or destination. -func (client Client) ListPolicies(appGUIDs ...string) ([]Policy, error) { +func (client *Client) ListPolicies(appGUIDs ...string) ([]Policy, error) { var request *cfnetworking.Request var err error if len(appGUIDs) == 0 { @@ -91,7 +91,7 @@ func (client Client) ListPolicies(appGUIDs ...string) ([]Policy, error) { } // RemovePolicies will remove the network policy with the given parameters. -func (client Client) RemovePolicies(policies []Policy) error { +func (client *Client) RemovePolicies(policies []Policy) error { rawJSON, err := json.Marshal(PolicyList{Policies: policies}) if err != nil { return err diff --git a/api/cfnetworking/cfnetv1/policy_test.go b/api/cfnetworking/cfnetv1/policy_test.go index 9a337fbc1e0..ac8320a094c 100644 --- a/api/cfnetworking/cfnetv1/policy_test.go +++ b/api/cfnetworking/cfnetv1/policy_test.go @@ -3,9 +3,9 @@ package cfnetv1_test import ( "net/http" - . "code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/cfnetv1" - "code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/networkerror" - . "github.com/onsi/ginkgo" + . "code.cloudfoundry.org/cli/v8/api/cfnetworking/cfnetv1" + "code.cloudfoundry.org/cli/v8/api/cfnetworking/networkerror" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" ) diff --git a/api/cfnetworking/cfnetworking.go b/api/cfnetworking/cfnetworking.go new file mode 100644 index 00000000000..93b0cacabd5 --- /dev/null +++ b/api/cfnetworking/cfnetworking.go @@ -0,0 +1,6 @@ +// CF networking API. Copied from code.cloudfoundry.org/cfnetworking-cli-api +// to reduce recursive dependencies and allow proper go module management. + +package cfnetworking + +//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate diff --git a/api/cfnetworking/cfnetworking_suite_test.go b/api/cfnetworking/cfnetworking_suite_test.go index 5ed7ecab053..b434160e526 100644 --- a/api/cfnetworking/cfnetworking_suite_test.go +++ b/api/cfnetworking/cfnetworking_suite_test.go @@ -5,7 +5,7 @@ import ( "log" "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" ) diff --git a/api/cfnetworking/cfnetworkingfakes/fake_connection.go b/api/cfnetworking/cfnetworkingfakes/fake_connection.go index 16278609210..76952cd561b 100644 --- a/api/cfnetworking/cfnetworkingfakes/fake_connection.go +++ b/api/cfnetworking/cfnetworkingfakes/fake_connection.go @@ -8,11 +8,11 @@ import ( ) type FakeConnection struct { - MakeStub func(request *cfnetworking.Request, passedResponse *cfnetworking.Response) error + MakeStub func(*cfnetworking.Request, *cfnetworking.Response) error makeMutex sync.RWMutex makeArgsForCall []struct { - request *cfnetworking.Request - passedResponse *cfnetworking.Response + arg1 *cfnetworking.Request + arg2 *cfnetworking.Response } makeReturns struct { result1 error @@ -24,22 +24,24 @@ type FakeConnection struct { invocationsMutex sync.RWMutex } -func (fake *FakeConnection) Make(request *cfnetworking.Request, passedResponse *cfnetworking.Response) error { +func (fake *FakeConnection) Make(arg1 *cfnetworking.Request, arg2 *cfnetworking.Response) error { fake.makeMutex.Lock() ret, specificReturn := fake.makeReturnsOnCall[len(fake.makeArgsForCall)] fake.makeArgsForCall = append(fake.makeArgsForCall, struct { - request *cfnetworking.Request - passedResponse *cfnetworking.Response - }{request, passedResponse}) - fake.recordInvocation("Make", []interface{}{request, passedResponse}) + arg1 *cfnetworking.Request + arg2 *cfnetworking.Response + }{arg1, arg2}) + stub := fake.MakeStub + fakeReturns := fake.makeReturns + fake.recordInvocation("Make", []interface{}{arg1, arg2}) fake.makeMutex.Unlock() - if fake.MakeStub != nil { - return fake.MakeStub(request, passedResponse) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - return fake.makeReturns.result1 + return fakeReturns.result1 } func (fake *FakeConnection) MakeCallCount() int { @@ -48,13 +50,22 @@ func (fake *FakeConnection) MakeCallCount() int { return len(fake.makeArgsForCall) } +func (fake *FakeConnection) MakeCalls(stub func(*cfnetworking.Request, *cfnetworking.Response) error) { + fake.makeMutex.Lock() + defer fake.makeMutex.Unlock() + fake.MakeStub = stub +} + func (fake *FakeConnection) MakeArgsForCall(i int) (*cfnetworking.Request, *cfnetworking.Response) { fake.makeMutex.RLock() defer fake.makeMutex.RUnlock() - return fake.makeArgsForCall[i].request, fake.makeArgsForCall[i].passedResponse + argsForCall := fake.makeArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeConnection) MakeReturns(result1 error) { + fake.makeMutex.Lock() + defer fake.makeMutex.Unlock() fake.MakeStub = nil fake.makeReturns = struct { result1 error @@ -62,6 +73,8 @@ func (fake *FakeConnection) MakeReturns(result1 error) { } func (fake *FakeConnection) MakeReturnsOnCall(i int, result1 error) { + fake.makeMutex.Lock() + defer fake.makeMutex.Unlock() fake.MakeStub = nil if fake.makeReturnsOnCall == nil { fake.makeReturnsOnCall = make(map[int]struct { diff --git a/api/cfnetworking/cfnetworkingfakes/fake_read_seeker.go b/api/cfnetworking/cfnetworkingfakes/fake_read_seeker.go index ac73fc39593..ef98c43a164 100644 --- a/api/cfnetworking/cfnetworkingfakes/fake_read_seeker.go +++ b/api/cfnetworking/cfnetworkingfakes/fake_read_seeker.go @@ -8,10 +8,10 @@ import ( ) type FakeReadSeeker struct { - ReadStub func(p []byte) (n int, err error) + ReadStub func([]byte) (int, error) readMutex sync.RWMutex readArgsForCall []struct { - p []byte + arg1 []byte } readReturns struct { result1 int @@ -21,11 +21,11 @@ type FakeReadSeeker struct { result1 int result2 error } - SeekStub func(offset int64, whence int) (int64, error) + SeekStub func(int64, int) (int64, error) seekMutex sync.RWMutex seekArgsForCall []struct { - offset int64 - whence int + arg1 int64 + arg2 int } seekReturns struct { result1 int64 @@ -39,26 +39,28 @@ type FakeReadSeeker struct { invocationsMutex sync.RWMutex } -func (fake *FakeReadSeeker) Read(p []byte) (n int, err error) { - var pCopy []byte - if p != nil { - pCopy = make([]byte, len(p)) - copy(pCopy, p) +func (fake *FakeReadSeeker) Read(arg1 []byte) (int, error) { + var arg1Copy []byte + if arg1 != nil { + arg1Copy = make([]byte, len(arg1)) + copy(arg1Copy, arg1) } fake.readMutex.Lock() ret, specificReturn := fake.readReturnsOnCall[len(fake.readArgsForCall)] fake.readArgsForCall = append(fake.readArgsForCall, struct { - p []byte - }{pCopy}) - fake.recordInvocation("Read", []interface{}{pCopy}) + arg1 []byte + }{arg1Copy}) + stub := fake.ReadStub + fakeReturns := fake.readReturns + fake.recordInvocation("Read", []interface{}{arg1Copy}) fake.readMutex.Unlock() - if fake.ReadStub != nil { - return fake.ReadStub(p) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } - return fake.readReturns.result1, fake.readReturns.result2 + return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeReadSeeker) ReadCallCount() int { @@ -67,13 +69,22 @@ func (fake *FakeReadSeeker) ReadCallCount() int { return len(fake.readArgsForCall) } +func (fake *FakeReadSeeker) ReadCalls(stub func([]byte) (int, error)) { + fake.readMutex.Lock() + defer fake.readMutex.Unlock() + fake.ReadStub = stub +} + func (fake *FakeReadSeeker) ReadArgsForCall(i int) []byte { fake.readMutex.RLock() defer fake.readMutex.RUnlock() - return fake.readArgsForCall[i].p + argsForCall := fake.readArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeReadSeeker) ReadReturns(result1 int, result2 error) { + fake.readMutex.Lock() + defer fake.readMutex.Unlock() fake.ReadStub = nil fake.readReturns = struct { result1 int @@ -82,6 +93,8 @@ func (fake *FakeReadSeeker) ReadReturns(result1 int, result2 error) { } func (fake *FakeReadSeeker) ReadReturnsOnCall(i int, result1 int, result2 error) { + fake.readMutex.Lock() + defer fake.readMutex.Unlock() fake.ReadStub = nil if fake.readReturnsOnCall == nil { fake.readReturnsOnCall = make(map[int]struct { @@ -95,22 +108,24 @@ func (fake *FakeReadSeeker) ReadReturnsOnCall(i int, result1 int, result2 error) }{result1, result2} } -func (fake *FakeReadSeeker) Seek(offset int64, whence int) (int64, error) { +func (fake *FakeReadSeeker) Seek(arg1 int64, arg2 int) (int64, error) { fake.seekMutex.Lock() ret, specificReturn := fake.seekReturnsOnCall[len(fake.seekArgsForCall)] fake.seekArgsForCall = append(fake.seekArgsForCall, struct { - offset int64 - whence int - }{offset, whence}) - fake.recordInvocation("Seek", []interface{}{offset, whence}) + arg1 int64 + arg2 int + }{arg1, arg2}) + stub := fake.SeekStub + fakeReturns := fake.seekReturns + fake.recordInvocation("Seek", []interface{}{arg1, arg2}) fake.seekMutex.Unlock() - if fake.SeekStub != nil { - return fake.SeekStub(offset, whence) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } - return fake.seekReturns.result1, fake.seekReturns.result2 + return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeReadSeeker) SeekCallCount() int { @@ -119,13 +134,22 @@ func (fake *FakeReadSeeker) SeekCallCount() int { return len(fake.seekArgsForCall) } +func (fake *FakeReadSeeker) SeekCalls(stub func(int64, int) (int64, error)) { + fake.seekMutex.Lock() + defer fake.seekMutex.Unlock() + fake.SeekStub = stub +} + func (fake *FakeReadSeeker) SeekArgsForCall(i int) (int64, int) { fake.seekMutex.RLock() defer fake.seekMutex.RUnlock() - return fake.seekArgsForCall[i].offset, fake.seekArgsForCall[i].whence + argsForCall := fake.seekArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeReadSeeker) SeekReturns(result1 int64, result2 error) { + fake.seekMutex.Lock() + defer fake.seekMutex.Unlock() fake.SeekStub = nil fake.seekReturns = struct { result1 int64 @@ -134,6 +158,8 @@ func (fake *FakeReadSeeker) SeekReturns(result1 int64, result2 error) { } func (fake *FakeReadSeeker) SeekReturnsOnCall(i int, result1 int64, result2 error) { + fake.seekMutex.Lock() + defer fake.seekMutex.Unlock() fake.SeekStub = nil if fake.seekReturnsOnCall == nil { fake.seekReturnsOnCall = make(map[int]struct { diff --git a/api/cfnetworking/connection.go b/api/cfnetworking/connection.go index bcc6548a93b..96958130dcf 100644 --- a/api/cfnetworking/connection.go +++ b/api/cfnetworking/connection.go @@ -1,8 +1,8 @@ package cfnetworking -//go:generate counterfeiter . Connection - // Connection creates and executes http requests +// +//counterfeiter:generate . Connection type Connection interface { Make(request *Request, passedResponse *Response) error } diff --git a/api/cfnetworking/errors_test.go b/api/cfnetworking/errors_test.go index ecfada59e49..65e9d86f5a6 100644 --- a/api/cfnetworking/errors_test.go +++ b/api/cfnetworking/errors_test.go @@ -8,8 +8,7 @@ import ( "code.cloudfoundry.org/cli/v8/api/cfnetworking/cfnetworkingfakes" "code.cloudfoundry.org/cli/v8/api/cfnetworking/networkerror" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/api/cfnetworking/networkerror/request_error.go b/api/cfnetworking/networkerror/request_error.go index 7b0ff48937f..0a4c17a6f72 100644 --- a/api/cfnetworking/networkerror/request_error.go +++ b/api/cfnetworking/networkerror/request_error.go @@ -1,7 +1,7 @@ package networkerror // RequestError represents a generic error encountered while performing the -// HTTP request. This generic error occurs before a HTTP response is obtained. +// HTTP request. This generic error occurs before an HTTP response is obtained. type RequestError struct { Err error } diff --git a/api/cfnetworking/networkerror/unverified_server_error.go b/api/cfnetworking/networkerror/unverified_server_error.go index 59a877302a8..97b7992e614 100644 --- a/api/cfnetworking/networkerror/unverified_server_error.go +++ b/api/cfnetworking/networkerror/unverified_server_error.go @@ -1,7 +1,7 @@ package networkerror // UnverifiedServerError replaces x509.UnknownAuthorityError when the server -// has SSL but the client is unable to verify it's certificate +// has SSL but the client is unable to verify its certificate type UnverifiedServerError struct { URL string } diff --git a/api/cfnetworking/networking_connection.go b/api/cfnetworking/networking_connection.go index 4ea5d3649ea..e2fae7eb705 100644 --- a/api/cfnetworking/networking_connection.go +++ b/api/cfnetworking/networking_connection.go @@ -5,7 +5,8 @@ import ( "crypto/tls" "crypto/x509" "encoding/json" - "io/ioutil" + "errors" + "io" "net" "net/http" "net/url" @@ -50,7 +51,7 @@ func NewConnection(config Config) *NetworkingConnection { func (connection *NetworkingConnection) Make(request *Request, passedResponse *Response) error { // In case this function is called from a retry, passedResponse may already // be populated with a previous response. We reset in case there's an HTTP - // error and we don't repopulate it in populateResponse. + // error, and we don't repopulate it in populateResponse. passedResponse.reset() response, err := connection.HTTPClient.Do(request.Request) @@ -62,20 +63,20 @@ func (connection *NetworkingConnection) Make(request *Request, passedResponse *R } func (*NetworkingConnection) processRequestErrors(request *http.Request, err error) error { - switch e := err.(type) { + switch err.(type) { case *url.Error: - switch urlErr := e.Err.(type) { - case x509.UnknownAuthorityError: + if errors.As(err, &x509.UnknownAuthorityError{}) { return networkerror.UnverifiedServerError{ URL: request.URL.String(), } - case x509.HostnameError: + } + hostnameError := x509.HostnameError{} + if errors.As(err, &hostnameError) { return networkerror.SSLValidationHostnameError{ - Message: urlErr.Error(), + Message: hostnameError.Error(), } - default: - return networkerror.RequestError{Err: e} } + return networkerror.RequestError{Err: err} default: return err } @@ -88,7 +89,7 @@ func (connection *NetworkingConnection) populateResponse(response *http.Response passedResponse.ResourceLocationURL = resourceLocationURL } - rawBytes, err := ioutil.ReadAll(response.Body) + rawBytes, err := io.ReadAll(response.Body) defer response.Body.Close() if err != nil { return err diff --git a/api/cfnetworking/networking_connection_test.go b/api/cfnetworking/networking_connection_test.go index 488c05f657a..2c8f8072c8e 100644 --- a/api/cfnetworking/networking_connection_test.go +++ b/api/cfnetworking/networking_connection_test.go @@ -8,7 +8,7 @@ import ( . "code.cloudfoundry.org/cli/v8/api/cfnetworking" "code.cloudfoundry.org/cli/v8/api/cfnetworking/networkerror" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" ) @@ -48,7 +48,7 @@ var _ = Describe("CF Networking Connection", func() { request = &Request{Request: req} }) - Context("when passed a response with a result set", func() { + When("passed a response with a result set", func() { It("unmarshals the data into a struct", func() { var body DummyResponse response := Response{ @@ -74,7 +74,7 @@ var _ = Describe("CF Networking Connection", func() { }) }) - Context("when passed an empty response", func() { + When("passed an empty response", func() { It("skips the unmarshalling step", func() { var response Response err := connection.Make(request, &response) @@ -138,7 +138,7 @@ var _ = Describe("CF Networking Connection", func() { }) Describe("Errors", func() { - Context("when the server does not exist", func() { + When("the server does not exist", func() { BeforeEach(func() { connection = NewConnection(Config{}) }) @@ -158,7 +158,7 @@ var _ = Describe("CF Networking Connection", func() { }) }) - Context("when the server does not have a verified certificate", func() { + When("the server does not have a verified certificate", func() { Context("skipSSLValidation is false", func() { BeforeEach(func() { server.AppendHandlers( @@ -182,11 +182,11 @@ var _ = Describe("CF Networking Connection", func() { }) }) - Context("when the server's certificate does not match the hostname", func() { + When("the server's certificate does not match the hostname", func() { Context("skipSSLValidation is false", func() { BeforeEach(func() { - if runtime.GOOS == "windows" { - Skip("ssl validation has a different order on windows, will not be returned properly") + if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + Skip("ssl validation has a different order on windows/darwin, will not be returned properly") } server.AppendHandlers( CombineHandlers( @@ -197,9 +197,9 @@ var _ = Describe("CF Networking Connection", func() { connection = NewConnection(Config{}) }) - // loopback.cli.ci.cf-app.com is a custom DNS record setup to point to 127.0.0.1 + // loopback.cli.fun is a custom DNS record setup to point to 127.0.0.1 It("returns a SSLValidationHostnameError", func() { - altHostURL := strings.Replace(server.URL(), "127.0.0.1", "loopback.cli.ci.cf-app.com", -1) + altHostURL := strings.Replace(server.URL(), "127.0.0.1", "loopback.cli.fun", -1) req, err := http.NewRequest(http.MethodGet, altHostURL, nil) Expect(err).ToNot(HaveOccurred()) request := &Request{Request: req} @@ -207,7 +207,7 @@ var _ = Describe("CF Networking Connection", func() { var response Response err = connection.Make(request, &response) Expect(err).To(MatchError(networkerror.SSLValidationHostnameError{ - Message: "x509: certificate is valid for example.com, not loopback.cli.ci.cf-app.com", + Message: "x509: certificate is valid for example.com, not loopback.cli.fun", })) }) }) diff --git a/api/cfnetworking/request.go b/api/cfnetworking/request.go index 84f42ed9d76..8a81ca53897 100644 --- a/api/cfnetworking/request.go +++ b/api/cfnetworking/request.go @@ -5,8 +5,7 @@ import ( "net/http" ) -//go:generate counterfeiter . ReadSeeker - +//counterfeiter:generate . ReadSeeker type ReadSeeker interface { io.ReadSeeker } diff --git a/api/cfnetworking/wrapper/request_logger.go b/api/cfnetworking/wrapper/request_logger.go index d5dcab3690e..6918b8927f1 100644 --- a/api/cfnetworking/wrapper/request_logger.go +++ b/api/cfnetworking/wrapper/request_logger.go @@ -2,7 +2,7 @@ package wrapper import ( "fmt" - "io/ioutil" + "io" "net/http" "sort" "strings" @@ -11,9 +11,9 @@ import ( "code.cloudfoundry.org/cli/v8/api/cfnetworking" ) -//go:generate counterfeiter . RequestLoggerOutput - // RequestLoggerOutput is the interface for displaying logs +// +//counterfeiter:generate . RequestLoggerOutput type RequestLoggerOutput interface { DisplayHeader(name string, value string) error DisplayHost(name string) error @@ -93,7 +93,7 @@ func (logger *RequestLogger) displayRequest(request *cfnetworking.Request) error contentType := request.Header.Get("Content-Type") if request.Body != nil { if strings.Contains(contentType, "json") { - rawRequestBody, err := ioutil.ReadAll(request.Body) + rawRequestBody, err := io.ReadAll(request.Body) if err != nil { return err } @@ -131,8 +131,8 @@ func (logger *RequestLogger) displayResponse(passedResponse *cfnetworking.Respon } func (logger *RequestLogger) displaySortedHeaders(headers http.Header) error { - keys := []string{} - for key, _ := range headers { + keys := make([]string, 0) + for key := range headers { keys = append(keys, key) } sort.Strings(keys) diff --git a/api/cfnetworking/wrapper/request_logger_test.go b/api/cfnetworking/wrapper/request_logger_test.go index 3de55d002a0..5a24135c0be 100644 --- a/api/cfnetworking/wrapper/request_logger_test.go +++ b/api/cfnetworking/wrapper/request_logger_test.go @@ -3,7 +3,7 @@ package wrapper_test import ( "bytes" "errors" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -13,7 +13,7 @@ import ( . "code.cloudfoundry.org/cli/v8/api/cfnetworking/wrapper" "code.cloudfoundry.org/cli/v8/api/cfnetworking/wrapper/wrapperfakes" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -121,7 +121,7 @@ var _ = Describe("Request Logger", func() { Expect(fakeOutput.DisplayJSONBodyCallCount()).To(BeNumerically(">=", 1)) Expect(fakeOutput.DisplayJSONBodyArgsForCall(0)).To(Equal([]byte("foo"))) - bytes, err := ioutil.ReadAll(request.Body) + bytes, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(bytes).To(Equal([]byte("foo"))) }) diff --git a/api/cfnetworking/wrapper/retry_request_test.go b/api/cfnetworking/wrapper/retry_request_test.go index 2d865e2cc47..6c38d25b12d 100644 --- a/api/cfnetworking/wrapper/retry_request_test.go +++ b/api/cfnetworking/wrapper/retry_request_test.go @@ -2,7 +2,7 @@ package wrapper_test import ( "errors" - "io/ioutil" + "io" "net/http" "strings" @@ -10,8 +10,7 @@ import ( "code.cloudfoundry.org/cli/v8/api/cfnetworking/cfnetworkingfakes" "code.cloudfoundry.org/cli/v8/api/cfnetworking/networkerror" . "code.cloudfoundry.org/cli/v8/api/cfnetworking/wrapper" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -37,7 +36,7 @@ var _ = Describe("Retry Request", func() { } fakeConnection.MakeStub = func(req *cfnetworking.Request, passedResponse *cfnetworking.Response) error { defer req.Body.Close() - body, readBodyErr := ioutil.ReadAll(request.Body) + body, readBodyErr := io.ReadAll(request.Body) Expect(readBodyErr).ToNot(HaveOccurred()) Expect(string(body)).To(Equal(rawRequestBody)) return expectedErr diff --git a/api/cfnetworking/wrapper/uaa_authentication.go b/api/cfnetworking/wrapper/uaa_authentication.go index 2fabb9a63bd..3c9b816fca7 100644 --- a/api/cfnetworking/wrapper/uaa_authentication.go +++ b/api/cfnetworking/wrapper/uaa_authentication.go @@ -6,16 +6,16 @@ import ( "code.cloudfoundry.org/cli/v8/api/uaa" ) -//go:generate counterfeiter . UAAClient - // UAAClient is the interface for getting a valid access token +// +//counterfeiter:generate . UAAClient type UAAClient interface { RefreshAccessToken(refreshToken string) (uaa.RefreshedTokens, error) } -//go:generate counterfeiter . TokenCache - // TokenCache is where the UAA token information is stored. +// +//counterfeiter:generate . TokenCache type TokenCache interface { AccessToken() string RefreshToken() string diff --git a/api/cfnetworking/wrapper/uaa_authentication_test.go b/api/cfnetworking/wrapper/uaa_authentication_test.go index cab5eab2a23..d2d088275ef 100644 --- a/api/cfnetworking/wrapper/uaa_authentication_test.go +++ b/api/cfnetworking/wrapper/uaa_authentication_test.go @@ -2,7 +2,7 @@ package wrapper_test import ( "errors" - "io/ioutil" + "io" "net/http" "strings" @@ -14,7 +14,7 @@ import ( "code.cloudfoundry.org/cli/v8/api/uaa" "code.cloudfoundry.org/cli/v8/api/cfnetworking/networkerror" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -102,12 +102,12 @@ var _ = Describe("UAA Authentication", func() { body := strings.NewReader(expectedBody) request = cfnetworking.NewRequest(&http.Request{ Header: http.Header{}, - Body: ioutil.NopCloser(body), + Body: io.NopCloser(body), }, body) makeCount := 0 fakeConnection.MakeStub = func(request *cfnetworking.Request, response *cfnetworking.Response) error { - body, err := ioutil.ReadAll(request.Body) + body, err := io.ReadAll(request.Body) Expect(err).NotTo(HaveOccurred()) Expect(string(body)).To(Equal(expectedBody)) diff --git a/api/cfnetworking/wrapper/util/in_memory_cache.go b/api/cfnetworking/wrapper/util/in_memory_cache.go index 91ef7af265a..7e1f291fef5 100644 --- a/api/cfnetworking/wrapper/util/in_memory_cache.go +++ b/api/cfnetworking/wrapper/util/in_memory_cache.go @@ -5,11 +5,11 @@ type InMemoryCache struct { refreshToken string } -func (c InMemoryCache) AccessToken() string { +func (c *InMemoryCache) AccessToken() string { return c.accessToken } -func (c InMemoryCache) RefreshToken() string { +func (c *InMemoryCache) RefreshToken() string { return c.refreshToken } diff --git a/api/cfnetworking/wrapper/wrapper.go b/api/cfnetworking/wrapper/wrapper.go new file mode 100644 index 00000000000..c9964d98277 --- /dev/null +++ b/api/cfnetworking/wrapper/wrapper.go @@ -0,0 +1,3 @@ +package wrapper + +//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate diff --git a/api/cfnetworking/wrapper/wrapper_suite_test.go b/api/cfnetworking/wrapper/wrapper_suite_test.go index a56eec41d0c..36bb7436be4 100644 --- a/api/cfnetworking/wrapper/wrapper_suite_test.go +++ b/api/cfnetworking/wrapper/wrapper_suite_test.go @@ -3,12 +3,11 @@ package wrapper_test import ( "bytes" "log" + "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/ghttp" - - "testing" ) func TestWrapper(t *testing.T) { diff --git a/api/cfnetworking/wrapper/wrapperfakes/fake_request_logger_output.go b/api/cfnetworking/wrapper/wrapperfakes/fake_request_logger_output.go index 2808ff8cc49..7d83cc31669 100644 --- a/api/cfnetworking/wrapper/wrapperfakes/fake_request_logger_output.go +++ b/api/cfnetworking/wrapper/wrapperfakes/fake_request_logger_output.go @@ -9,11 +9,11 @@ import ( ) type FakeRequestLoggerOutput struct { - DisplayHeaderStub func(name string, value string) error + DisplayHeaderStub func(string, string) error displayHeaderMutex sync.RWMutex displayHeaderArgsForCall []struct { - name string - value string + arg1 string + arg2 string } displayHeaderReturns struct { result1 error @@ -21,10 +21,10 @@ type FakeRequestLoggerOutput struct { displayHeaderReturnsOnCall map[int]struct { result1 error } - DisplayHostStub func(name string) error + DisplayHostStub func(string) error displayHostMutex sync.RWMutex displayHostArgsForCall []struct { - name string + arg1 string } displayHostReturns struct { result1 error @@ -32,10 +32,10 @@ type FakeRequestLoggerOutput struct { displayHostReturnsOnCall map[int]struct { result1 error } - DisplayJSONBodyStub func(body []byte) error + DisplayJSONBodyStub func([]byte) error displayJSONBodyMutex sync.RWMutex displayJSONBodyArgsForCall []struct { - body []byte + arg1 []byte } displayJSONBodyReturns struct { result1 error @@ -43,10 +43,10 @@ type FakeRequestLoggerOutput struct { displayJSONBodyReturnsOnCall map[int]struct { result1 error } - DisplayMessageStub func(msg string) error + DisplayMessageStub func(string) error displayMessageMutex sync.RWMutex displayMessageArgsForCall []struct { - msg string + arg1 string } displayMessageReturns struct { result1 error @@ -54,12 +54,12 @@ type FakeRequestLoggerOutput struct { displayMessageReturnsOnCall map[int]struct { result1 error } - DisplayRequestHeaderStub func(method string, uri string, httpProtocol string) error + DisplayRequestHeaderStub func(string, string, string) error displayRequestHeaderMutex sync.RWMutex displayRequestHeaderArgsForCall []struct { - method string - uri string - httpProtocol string + arg1 string + arg2 string + arg3 string } displayRequestHeaderReturns struct { result1 error @@ -67,11 +67,11 @@ type FakeRequestLoggerOutput struct { displayRequestHeaderReturnsOnCall map[int]struct { result1 error } - DisplayResponseHeaderStub func(httpProtocol string, status string) error + DisplayResponseHeaderStub func(string, string) error displayResponseHeaderMutex sync.RWMutex displayResponseHeaderArgsForCall []struct { - httpProtocol string - status string + arg1 string + arg2 string } displayResponseHeaderReturns struct { result1 error @@ -79,11 +79,11 @@ type FakeRequestLoggerOutput struct { displayResponseHeaderReturnsOnCall map[int]struct { result1 error } - DisplayTypeStub func(name string, requestDate time.Time) error + DisplayTypeStub func(string, time.Time) error displayTypeMutex sync.RWMutex displayTypeArgsForCall []struct { - name string - requestDate time.Time + arg1 string + arg2 time.Time } displayTypeReturns struct { result1 error @@ -91,15 +91,16 @@ type FakeRequestLoggerOutput struct { displayTypeReturnsOnCall map[int]struct { result1 error } - HandleInternalErrorStub func(err error) + HandleInternalErrorStub func(error) handleInternalErrorMutex sync.RWMutex handleInternalErrorArgsForCall []struct { - err error + arg1 error } StartStub func() error startMutex sync.RWMutex - startArgsForCall []struct{} - startReturns struct { + startArgsForCall []struct { + } + startReturns struct { result1 error } startReturnsOnCall map[int]struct { @@ -107,8 +108,9 @@ type FakeRequestLoggerOutput struct { } StopStub func() error stopMutex sync.RWMutex - stopArgsForCall []struct{} - stopReturns struct { + stopArgsForCall []struct { + } + stopReturns struct { result1 error } stopReturnsOnCall map[int]struct { @@ -118,22 +120,24 @@ type FakeRequestLoggerOutput struct { invocationsMutex sync.RWMutex } -func (fake *FakeRequestLoggerOutput) DisplayHeader(name string, value string) error { +func (fake *FakeRequestLoggerOutput) DisplayHeader(arg1 string, arg2 string) error { fake.displayHeaderMutex.Lock() ret, specificReturn := fake.displayHeaderReturnsOnCall[len(fake.displayHeaderArgsForCall)] fake.displayHeaderArgsForCall = append(fake.displayHeaderArgsForCall, struct { - name string - value string - }{name, value}) - fake.recordInvocation("DisplayHeader", []interface{}{name, value}) + arg1 string + arg2 string + }{arg1, arg2}) + stub := fake.DisplayHeaderStub + fakeReturns := fake.displayHeaderReturns + fake.recordInvocation("DisplayHeader", []interface{}{arg1, arg2}) fake.displayHeaderMutex.Unlock() - if fake.DisplayHeaderStub != nil { - return fake.DisplayHeaderStub(name, value) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - return fake.displayHeaderReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) DisplayHeaderCallCount() int { @@ -142,13 +146,22 @@ func (fake *FakeRequestLoggerOutput) DisplayHeaderCallCount() int { return len(fake.displayHeaderArgsForCall) } +func (fake *FakeRequestLoggerOutput) DisplayHeaderCalls(stub func(string, string) error) { + fake.displayHeaderMutex.Lock() + defer fake.displayHeaderMutex.Unlock() + fake.DisplayHeaderStub = stub +} + func (fake *FakeRequestLoggerOutput) DisplayHeaderArgsForCall(i int) (string, string) { fake.displayHeaderMutex.RLock() defer fake.displayHeaderMutex.RUnlock() - return fake.displayHeaderArgsForCall[i].name, fake.displayHeaderArgsForCall[i].value + argsForCall := fake.displayHeaderArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeRequestLoggerOutput) DisplayHeaderReturns(result1 error) { + fake.displayHeaderMutex.Lock() + defer fake.displayHeaderMutex.Unlock() fake.DisplayHeaderStub = nil fake.displayHeaderReturns = struct { result1 error @@ -156,6 +169,8 @@ func (fake *FakeRequestLoggerOutput) DisplayHeaderReturns(result1 error) { } func (fake *FakeRequestLoggerOutput) DisplayHeaderReturnsOnCall(i int, result1 error) { + fake.displayHeaderMutex.Lock() + defer fake.displayHeaderMutex.Unlock() fake.DisplayHeaderStub = nil if fake.displayHeaderReturnsOnCall == nil { fake.displayHeaderReturnsOnCall = make(map[int]struct { @@ -167,21 +182,23 @@ func (fake *FakeRequestLoggerOutput) DisplayHeaderReturnsOnCall(i int, result1 e }{result1} } -func (fake *FakeRequestLoggerOutput) DisplayHost(name string) error { +func (fake *FakeRequestLoggerOutput) DisplayHost(arg1 string) error { fake.displayHostMutex.Lock() ret, specificReturn := fake.displayHostReturnsOnCall[len(fake.displayHostArgsForCall)] fake.displayHostArgsForCall = append(fake.displayHostArgsForCall, struct { - name string - }{name}) - fake.recordInvocation("DisplayHost", []interface{}{name}) + arg1 string + }{arg1}) + stub := fake.DisplayHostStub + fakeReturns := fake.displayHostReturns + fake.recordInvocation("DisplayHost", []interface{}{arg1}) fake.displayHostMutex.Unlock() - if fake.DisplayHostStub != nil { - return fake.DisplayHostStub(name) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1 } - return fake.displayHostReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) DisplayHostCallCount() int { @@ -190,13 +207,22 @@ func (fake *FakeRequestLoggerOutput) DisplayHostCallCount() int { return len(fake.displayHostArgsForCall) } +func (fake *FakeRequestLoggerOutput) DisplayHostCalls(stub func(string) error) { + fake.displayHostMutex.Lock() + defer fake.displayHostMutex.Unlock() + fake.DisplayHostStub = stub +} + func (fake *FakeRequestLoggerOutput) DisplayHostArgsForCall(i int) string { fake.displayHostMutex.RLock() defer fake.displayHostMutex.RUnlock() - return fake.displayHostArgsForCall[i].name + argsForCall := fake.displayHostArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeRequestLoggerOutput) DisplayHostReturns(result1 error) { + fake.displayHostMutex.Lock() + defer fake.displayHostMutex.Unlock() fake.DisplayHostStub = nil fake.displayHostReturns = struct { result1 error @@ -204,6 +230,8 @@ func (fake *FakeRequestLoggerOutput) DisplayHostReturns(result1 error) { } func (fake *FakeRequestLoggerOutput) DisplayHostReturnsOnCall(i int, result1 error) { + fake.displayHostMutex.Lock() + defer fake.displayHostMutex.Unlock() fake.DisplayHostStub = nil if fake.displayHostReturnsOnCall == nil { fake.displayHostReturnsOnCall = make(map[int]struct { @@ -215,26 +243,28 @@ func (fake *FakeRequestLoggerOutput) DisplayHostReturnsOnCall(i int, result1 err }{result1} } -func (fake *FakeRequestLoggerOutput) DisplayJSONBody(body []byte) error { - var bodyCopy []byte - if body != nil { - bodyCopy = make([]byte, len(body)) - copy(bodyCopy, body) +func (fake *FakeRequestLoggerOutput) DisplayJSONBody(arg1 []byte) error { + var arg1Copy []byte + if arg1 != nil { + arg1Copy = make([]byte, len(arg1)) + copy(arg1Copy, arg1) } fake.displayJSONBodyMutex.Lock() ret, specificReturn := fake.displayJSONBodyReturnsOnCall[len(fake.displayJSONBodyArgsForCall)] fake.displayJSONBodyArgsForCall = append(fake.displayJSONBodyArgsForCall, struct { - body []byte - }{bodyCopy}) - fake.recordInvocation("DisplayJSONBody", []interface{}{bodyCopy}) + arg1 []byte + }{arg1Copy}) + stub := fake.DisplayJSONBodyStub + fakeReturns := fake.displayJSONBodyReturns + fake.recordInvocation("DisplayJSONBody", []interface{}{arg1Copy}) fake.displayJSONBodyMutex.Unlock() - if fake.DisplayJSONBodyStub != nil { - return fake.DisplayJSONBodyStub(body) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1 } - return fake.displayJSONBodyReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) DisplayJSONBodyCallCount() int { @@ -243,13 +273,22 @@ func (fake *FakeRequestLoggerOutput) DisplayJSONBodyCallCount() int { return len(fake.displayJSONBodyArgsForCall) } +func (fake *FakeRequestLoggerOutput) DisplayJSONBodyCalls(stub func([]byte) error) { + fake.displayJSONBodyMutex.Lock() + defer fake.displayJSONBodyMutex.Unlock() + fake.DisplayJSONBodyStub = stub +} + func (fake *FakeRequestLoggerOutput) DisplayJSONBodyArgsForCall(i int) []byte { fake.displayJSONBodyMutex.RLock() defer fake.displayJSONBodyMutex.RUnlock() - return fake.displayJSONBodyArgsForCall[i].body + argsForCall := fake.displayJSONBodyArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeRequestLoggerOutput) DisplayJSONBodyReturns(result1 error) { + fake.displayJSONBodyMutex.Lock() + defer fake.displayJSONBodyMutex.Unlock() fake.DisplayJSONBodyStub = nil fake.displayJSONBodyReturns = struct { result1 error @@ -257,6 +296,8 @@ func (fake *FakeRequestLoggerOutput) DisplayJSONBodyReturns(result1 error) { } func (fake *FakeRequestLoggerOutput) DisplayJSONBodyReturnsOnCall(i int, result1 error) { + fake.displayJSONBodyMutex.Lock() + defer fake.displayJSONBodyMutex.Unlock() fake.DisplayJSONBodyStub = nil if fake.displayJSONBodyReturnsOnCall == nil { fake.displayJSONBodyReturnsOnCall = make(map[int]struct { @@ -268,21 +309,23 @@ func (fake *FakeRequestLoggerOutput) DisplayJSONBodyReturnsOnCall(i int, result1 }{result1} } -func (fake *FakeRequestLoggerOutput) DisplayMessage(msg string) error { +func (fake *FakeRequestLoggerOutput) DisplayMessage(arg1 string) error { fake.displayMessageMutex.Lock() ret, specificReturn := fake.displayMessageReturnsOnCall[len(fake.displayMessageArgsForCall)] fake.displayMessageArgsForCall = append(fake.displayMessageArgsForCall, struct { - msg string - }{msg}) - fake.recordInvocation("DisplayMessage", []interface{}{msg}) + arg1 string + }{arg1}) + stub := fake.DisplayMessageStub + fakeReturns := fake.displayMessageReturns + fake.recordInvocation("DisplayMessage", []interface{}{arg1}) fake.displayMessageMutex.Unlock() - if fake.DisplayMessageStub != nil { - return fake.DisplayMessageStub(msg) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1 } - return fake.displayMessageReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) DisplayMessageCallCount() int { @@ -291,13 +334,22 @@ func (fake *FakeRequestLoggerOutput) DisplayMessageCallCount() int { return len(fake.displayMessageArgsForCall) } +func (fake *FakeRequestLoggerOutput) DisplayMessageCalls(stub func(string) error) { + fake.displayMessageMutex.Lock() + defer fake.displayMessageMutex.Unlock() + fake.DisplayMessageStub = stub +} + func (fake *FakeRequestLoggerOutput) DisplayMessageArgsForCall(i int) string { fake.displayMessageMutex.RLock() defer fake.displayMessageMutex.RUnlock() - return fake.displayMessageArgsForCall[i].msg + argsForCall := fake.displayMessageArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeRequestLoggerOutput) DisplayMessageReturns(result1 error) { + fake.displayMessageMutex.Lock() + defer fake.displayMessageMutex.Unlock() fake.DisplayMessageStub = nil fake.displayMessageReturns = struct { result1 error @@ -305,6 +357,8 @@ func (fake *FakeRequestLoggerOutput) DisplayMessageReturns(result1 error) { } func (fake *FakeRequestLoggerOutput) DisplayMessageReturnsOnCall(i int, result1 error) { + fake.displayMessageMutex.Lock() + defer fake.displayMessageMutex.Unlock() fake.DisplayMessageStub = nil if fake.displayMessageReturnsOnCall == nil { fake.displayMessageReturnsOnCall = make(map[int]struct { @@ -316,23 +370,25 @@ func (fake *FakeRequestLoggerOutput) DisplayMessageReturnsOnCall(i int, result1 }{result1} } -func (fake *FakeRequestLoggerOutput) DisplayRequestHeader(method string, uri string, httpProtocol string) error { +func (fake *FakeRequestLoggerOutput) DisplayRequestHeader(arg1 string, arg2 string, arg3 string) error { fake.displayRequestHeaderMutex.Lock() ret, specificReturn := fake.displayRequestHeaderReturnsOnCall[len(fake.displayRequestHeaderArgsForCall)] fake.displayRequestHeaderArgsForCall = append(fake.displayRequestHeaderArgsForCall, struct { - method string - uri string - httpProtocol string - }{method, uri, httpProtocol}) - fake.recordInvocation("DisplayRequestHeader", []interface{}{method, uri, httpProtocol}) + arg1 string + arg2 string + arg3 string + }{arg1, arg2, arg3}) + stub := fake.DisplayRequestHeaderStub + fakeReturns := fake.displayRequestHeaderReturns + fake.recordInvocation("DisplayRequestHeader", []interface{}{arg1, arg2, arg3}) fake.displayRequestHeaderMutex.Unlock() - if fake.DisplayRequestHeaderStub != nil { - return fake.DisplayRequestHeaderStub(method, uri, httpProtocol) + if stub != nil { + return stub(arg1, arg2, arg3) } if specificReturn { return ret.result1 } - return fake.displayRequestHeaderReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderCallCount() int { @@ -341,13 +397,22 @@ func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderCallCount() int { return len(fake.displayRequestHeaderArgsForCall) } +func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderCalls(stub func(string, string, string) error) { + fake.displayRequestHeaderMutex.Lock() + defer fake.displayRequestHeaderMutex.Unlock() + fake.DisplayRequestHeaderStub = stub +} + func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderArgsForCall(i int) (string, string, string) { fake.displayRequestHeaderMutex.RLock() defer fake.displayRequestHeaderMutex.RUnlock() - return fake.displayRequestHeaderArgsForCall[i].method, fake.displayRequestHeaderArgsForCall[i].uri, fake.displayRequestHeaderArgsForCall[i].httpProtocol + argsForCall := fake.displayRequestHeaderArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderReturns(result1 error) { + fake.displayRequestHeaderMutex.Lock() + defer fake.displayRequestHeaderMutex.Unlock() fake.DisplayRequestHeaderStub = nil fake.displayRequestHeaderReturns = struct { result1 error @@ -355,6 +420,8 @@ func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderReturns(result1 error) } func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderReturnsOnCall(i int, result1 error) { + fake.displayRequestHeaderMutex.Lock() + defer fake.displayRequestHeaderMutex.Unlock() fake.DisplayRequestHeaderStub = nil if fake.displayRequestHeaderReturnsOnCall == nil { fake.displayRequestHeaderReturnsOnCall = make(map[int]struct { @@ -366,22 +433,24 @@ func (fake *FakeRequestLoggerOutput) DisplayRequestHeaderReturnsOnCall(i int, re }{result1} } -func (fake *FakeRequestLoggerOutput) DisplayResponseHeader(httpProtocol string, status string) error { +func (fake *FakeRequestLoggerOutput) DisplayResponseHeader(arg1 string, arg2 string) error { fake.displayResponseHeaderMutex.Lock() ret, specificReturn := fake.displayResponseHeaderReturnsOnCall[len(fake.displayResponseHeaderArgsForCall)] fake.displayResponseHeaderArgsForCall = append(fake.displayResponseHeaderArgsForCall, struct { - httpProtocol string - status string - }{httpProtocol, status}) - fake.recordInvocation("DisplayResponseHeader", []interface{}{httpProtocol, status}) + arg1 string + arg2 string + }{arg1, arg2}) + stub := fake.DisplayResponseHeaderStub + fakeReturns := fake.displayResponseHeaderReturns + fake.recordInvocation("DisplayResponseHeader", []interface{}{arg1, arg2}) fake.displayResponseHeaderMutex.Unlock() - if fake.DisplayResponseHeaderStub != nil { - return fake.DisplayResponseHeaderStub(httpProtocol, status) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - return fake.displayResponseHeaderReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderCallCount() int { @@ -390,13 +459,22 @@ func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderCallCount() int { return len(fake.displayResponseHeaderArgsForCall) } +func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderCalls(stub func(string, string) error) { + fake.displayResponseHeaderMutex.Lock() + defer fake.displayResponseHeaderMutex.Unlock() + fake.DisplayResponseHeaderStub = stub +} + func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderArgsForCall(i int) (string, string) { fake.displayResponseHeaderMutex.RLock() defer fake.displayResponseHeaderMutex.RUnlock() - return fake.displayResponseHeaderArgsForCall[i].httpProtocol, fake.displayResponseHeaderArgsForCall[i].status + argsForCall := fake.displayResponseHeaderArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderReturns(result1 error) { + fake.displayResponseHeaderMutex.Lock() + defer fake.displayResponseHeaderMutex.Unlock() fake.DisplayResponseHeaderStub = nil fake.displayResponseHeaderReturns = struct { result1 error @@ -404,6 +482,8 @@ func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderReturns(result1 error) } func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderReturnsOnCall(i int, result1 error) { + fake.displayResponseHeaderMutex.Lock() + defer fake.displayResponseHeaderMutex.Unlock() fake.DisplayResponseHeaderStub = nil if fake.displayResponseHeaderReturnsOnCall == nil { fake.displayResponseHeaderReturnsOnCall = make(map[int]struct { @@ -415,22 +495,24 @@ func (fake *FakeRequestLoggerOutput) DisplayResponseHeaderReturnsOnCall(i int, r }{result1} } -func (fake *FakeRequestLoggerOutput) DisplayType(name string, requestDate time.Time) error { +func (fake *FakeRequestLoggerOutput) DisplayType(arg1 string, arg2 time.Time) error { fake.displayTypeMutex.Lock() ret, specificReturn := fake.displayTypeReturnsOnCall[len(fake.displayTypeArgsForCall)] fake.displayTypeArgsForCall = append(fake.displayTypeArgsForCall, struct { - name string - requestDate time.Time - }{name, requestDate}) - fake.recordInvocation("DisplayType", []interface{}{name, requestDate}) + arg1 string + arg2 time.Time + }{arg1, arg2}) + stub := fake.DisplayTypeStub + fakeReturns := fake.displayTypeReturns + fake.recordInvocation("DisplayType", []interface{}{arg1, arg2}) fake.displayTypeMutex.Unlock() - if fake.DisplayTypeStub != nil { - return fake.DisplayTypeStub(name, requestDate) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - return fake.displayTypeReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) DisplayTypeCallCount() int { @@ -439,13 +521,22 @@ func (fake *FakeRequestLoggerOutput) DisplayTypeCallCount() int { return len(fake.displayTypeArgsForCall) } +func (fake *FakeRequestLoggerOutput) DisplayTypeCalls(stub func(string, time.Time) error) { + fake.displayTypeMutex.Lock() + defer fake.displayTypeMutex.Unlock() + fake.DisplayTypeStub = stub +} + func (fake *FakeRequestLoggerOutput) DisplayTypeArgsForCall(i int) (string, time.Time) { fake.displayTypeMutex.RLock() defer fake.displayTypeMutex.RUnlock() - return fake.displayTypeArgsForCall[i].name, fake.displayTypeArgsForCall[i].requestDate + argsForCall := fake.displayTypeArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 } func (fake *FakeRequestLoggerOutput) DisplayTypeReturns(result1 error) { + fake.displayTypeMutex.Lock() + defer fake.displayTypeMutex.Unlock() fake.DisplayTypeStub = nil fake.displayTypeReturns = struct { result1 error @@ -453,6 +544,8 @@ func (fake *FakeRequestLoggerOutput) DisplayTypeReturns(result1 error) { } func (fake *FakeRequestLoggerOutput) DisplayTypeReturnsOnCall(i int, result1 error) { + fake.displayTypeMutex.Lock() + defer fake.displayTypeMutex.Unlock() fake.DisplayTypeStub = nil if fake.displayTypeReturnsOnCall == nil { fake.displayTypeReturnsOnCall = make(map[int]struct { @@ -464,15 +557,16 @@ func (fake *FakeRequestLoggerOutput) DisplayTypeReturnsOnCall(i int, result1 err }{result1} } -func (fake *FakeRequestLoggerOutput) HandleInternalError(err error) { +func (fake *FakeRequestLoggerOutput) HandleInternalError(arg1 error) { fake.handleInternalErrorMutex.Lock() fake.handleInternalErrorArgsForCall = append(fake.handleInternalErrorArgsForCall, struct { - err error - }{err}) - fake.recordInvocation("HandleInternalError", []interface{}{err}) + arg1 error + }{arg1}) + stub := fake.HandleInternalErrorStub + fake.recordInvocation("HandleInternalError", []interface{}{arg1}) fake.handleInternalErrorMutex.Unlock() - if fake.HandleInternalErrorStub != nil { - fake.HandleInternalErrorStub(err) + if stub != nil { + fake.HandleInternalErrorStub(arg1) } } @@ -482,25 +576,35 @@ func (fake *FakeRequestLoggerOutput) HandleInternalErrorCallCount() int { return len(fake.handleInternalErrorArgsForCall) } +func (fake *FakeRequestLoggerOutput) HandleInternalErrorCalls(stub func(error)) { + fake.handleInternalErrorMutex.Lock() + defer fake.handleInternalErrorMutex.Unlock() + fake.HandleInternalErrorStub = stub +} + func (fake *FakeRequestLoggerOutput) HandleInternalErrorArgsForCall(i int) error { fake.handleInternalErrorMutex.RLock() defer fake.handleInternalErrorMutex.RUnlock() - return fake.handleInternalErrorArgsForCall[i].err + argsForCall := fake.handleInternalErrorArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeRequestLoggerOutput) Start() error { fake.startMutex.Lock() ret, specificReturn := fake.startReturnsOnCall[len(fake.startArgsForCall)] - fake.startArgsForCall = append(fake.startArgsForCall, struct{}{}) + fake.startArgsForCall = append(fake.startArgsForCall, struct { + }{}) + stub := fake.StartStub + fakeReturns := fake.startReturns fake.recordInvocation("Start", []interface{}{}) fake.startMutex.Unlock() - if fake.StartStub != nil { - return fake.StartStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - return fake.startReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) StartCallCount() int { @@ -509,7 +613,15 @@ func (fake *FakeRequestLoggerOutput) StartCallCount() int { return len(fake.startArgsForCall) } +func (fake *FakeRequestLoggerOutput) StartCalls(stub func() error) { + fake.startMutex.Lock() + defer fake.startMutex.Unlock() + fake.StartStub = stub +} + func (fake *FakeRequestLoggerOutput) StartReturns(result1 error) { + fake.startMutex.Lock() + defer fake.startMutex.Unlock() fake.StartStub = nil fake.startReturns = struct { result1 error @@ -517,6 +629,8 @@ func (fake *FakeRequestLoggerOutput) StartReturns(result1 error) { } func (fake *FakeRequestLoggerOutput) StartReturnsOnCall(i int, result1 error) { + fake.startMutex.Lock() + defer fake.startMutex.Unlock() fake.StartStub = nil if fake.startReturnsOnCall == nil { fake.startReturnsOnCall = make(map[int]struct { @@ -531,16 +645,19 @@ func (fake *FakeRequestLoggerOutput) StartReturnsOnCall(i int, result1 error) { func (fake *FakeRequestLoggerOutput) Stop() error { fake.stopMutex.Lock() ret, specificReturn := fake.stopReturnsOnCall[len(fake.stopArgsForCall)] - fake.stopArgsForCall = append(fake.stopArgsForCall, struct{}{}) + fake.stopArgsForCall = append(fake.stopArgsForCall, struct { + }{}) + stub := fake.StopStub + fakeReturns := fake.stopReturns fake.recordInvocation("Stop", []interface{}{}) fake.stopMutex.Unlock() - if fake.StopStub != nil { - return fake.StopStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - return fake.stopReturns.result1 + return fakeReturns.result1 } func (fake *FakeRequestLoggerOutput) StopCallCount() int { @@ -549,7 +666,15 @@ func (fake *FakeRequestLoggerOutput) StopCallCount() int { return len(fake.stopArgsForCall) } +func (fake *FakeRequestLoggerOutput) StopCalls(stub func() error) { + fake.stopMutex.Lock() + defer fake.stopMutex.Unlock() + fake.StopStub = stub +} + func (fake *FakeRequestLoggerOutput) StopReturns(result1 error) { + fake.stopMutex.Lock() + defer fake.stopMutex.Unlock() fake.StopStub = nil fake.stopReturns = struct { result1 error @@ -557,6 +682,8 @@ func (fake *FakeRequestLoggerOutput) StopReturns(result1 error) { } func (fake *FakeRequestLoggerOutput) StopReturnsOnCall(i int, result1 error) { + fake.stopMutex.Lock() + defer fake.stopMutex.Unlock() fake.StopStub = nil if fake.stopReturnsOnCall == nil { fake.stopReturnsOnCall = make(map[int]struct { diff --git a/api/cfnetworking/wrapper/wrapperfakes/fake_token_cache.go b/api/cfnetworking/wrapper/wrapperfakes/fake_token_cache.go index 71ef0ff109c..7c5f78f9f84 100644 --- a/api/cfnetworking/wrapper/wrapperfakes/fake_token_cache.go +++ b/api/cfnetworking/wrapper/wrapperfakes/fake_token_cache.go @@ -10,8 +10,9 @@ import ( type FakeTokenCache struct { AccessTokenStub func() string accessTokenMutex sync.RWMutex - accessTokenArgsForCall []struct{} - accessTokenReturns struct { + accessTokenArgsForCall []struct { + } + accessTokenReturns struct { result1 string } accessTokenReturnsOnCall map[int]struct { @@ -19,22 +20,23 @@ type FakeTokenCache struct { } RefreshTokenStub func() string refreshTokenMutex sync.RWMutex - refreshTokenArgsForCall []struct{} - refreshTokenReturns struct { + refreshTokenArgsForCall []struct { + } + refreshTokenReturns struct { result1 string } refreshTokenReturnsOnCall map[int]struct { result1 string } - SetAccessTokenStub func(token string) + SetAccessTokenStub func(string) setAccessTokenMutex sync.RWMutex setAccessTokenArgsForCall []struct { - token string + arg1 string } - SetRefreshTokenStub func(token string) + SetRefreshTokenStub func(string) setRefreshTokenMutex sync.RWMutex setRefreshTokenArgsForCall []struct { - token string + arg1 string } invocations map[string][][]interface{} invocationsMutex sync.RWMutex @@ -43,16 +45,19 @@ type FakeTokenCache struct { func (fake *FakeTokenCache) AccessToken() string { fake.accessTokenMutex.Lock() ret, specificReturn := fake.accessTokenReturnsOnCall[len(fake.accessTokenArgsForCall)] - fake.accessTokenArgsForCall = append(fake.accessTokenArgsForCall, struct{}{}) + fake.accessTokenArgsForCall = append(fake.accessTokenArgsForCall, struct { + }{}) + stub := fake.AccessTokenStub + fakeReturns := fake.accessTokenReturns fake.recordInvocation("AccessToken", []interface{}{}) fake.accessTokenMutex.Unlock() - if fake.AccessTokenStub != nil { - return fake.AccessTokenStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - return fake.accessTokenReturns.result1 + return fakeReturns.result1 } func (fake *FakeTokenCache) AccessTokenCallCount() int { @@ -61,7 +66,15 @@ func (fake *FakeTokenCache) AccessTokenCallCount() int { return len(fake.accessTokenArgsForCall) } +func (fake *FakeTokenCache) AccessTokenCalls(stub func() string) { + fake.accessTokenMutex.Lock() + defer fake.accessTokenMutex.Unlock() + fake.AccessTokenStub = stub +} + func (fake *FakeTokenCache) AccessTokenReturns(result1 string) { + fake.accessTokenMutex.Lock() + defer fake.accessTokenMutex.Unlock() fake.AccessTokenStub = nil fake.accessTokenReturns = struct { result1 string @@ -69,6 +82,8 @@ func (fake *FakeTokenCache) AccessTokenReturns(result1 string) { } func (fake *FakeTokenCache) AccessTokenReturnsOnCall(i int, result1 string) { + fake.accessTokenMutex.Lock() + defer fake.accessTokenMutex.Unlock() fake.AccessTokenStub = nil if fake.accessTokenReturnsOnCall == nil { fake.accessTokenReturnsOnCall = make(map[int]struct { @@ -83,16 +98,19 @@ func (fake *FakeTokenCache) AccessTokenReturnsOnCall(i int, result1 string) { func (fake *FakeTokenCache) RefreshToken() string { fake.refreshTokenMutex.Lock() ret, specificReturn := fake.refreshTokenReturnsOnCall[len(fake.refreshTokenArgsForCall)] - fake.refreshTokenArgsForCall = append(fake.refreshTokenArgsForCall, struct{}{}) + fake.refreshTokenArgsForCall = append(fake.refreshTokenArgsForCall, struct { + }{}) + stub := fake.RefreshTokenStub + fakeReturns := fake.refreshTokenReturns fake.recordInvocation("RefreshToken", []interface{}{}) fake.refreshTokenMutex.Unlock() - if fake.RefreshTokenStub != nil { - return fake.RefreshTokenStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1 } - return fake.refreshTokenReturns.result1 + return fakeReturns.result1 } func (fake *FakeTokenCache) RefreshTokenCallCount() int { @@ -101,7 +119,15 @@ func (fake *FakeTokenCache) RefreshTokenCallCount() int { return len(fake.refreshTokenArgsForCall) } +func (fake *FakeTokenCache) RefreshTokenCalls(stub func() string) { + fake.refreshTokenMutex.Lock() + defer fake.refreshTokenMutex.Unlock() + fake.RefreshTokenStub = stub +} + func (fake *FakeTokenCache) RefreshTokenReturns(result1 string) { + fake.refreshTokenMutex.Lock() + defer fake.refreshTokenMutex.Unlock() fake.RefreshTokenStub = nil fake.refreshTokenReturns = struct { result1 string @@ -109,6 +135,8 @@ func (fake *FakeTokenCache) RefreshTokenReturns(result1 string) { } func (fake *FakeTokenCache) RefreshTokenReturnsOnCall(i int, result1 string) { + fake.refreshTokenMutex.Lock() + defer fake.refreshTokenMutex.Unlock() fake.RefreshTokenStub = nil if fake.refreshTokenReturnsOnCall == nil { fake.refreshTokenReturnsOnCall = make(map[int]struct { @@ -120,15 +148,16 @@ func (fake *FakeTokenCache) RefreshTokenReturnsOnCall(i int, result1 string) { }{result1} } -func (fake *FakeTokenCache) SetAccessToken(token string) { +func (fake *FakeTokenCache) SetAccessToken(arg1 string) { fake.setAccessTokenMutex.Lock() fake.setAccessTokenArgsForCall = append(fake.setAccessTokenArgsForCall, struct { - token string - }{token}) - fake.recordInvocation("SetAccessToken", []interface{}{token}) + arg1 string + }{arg1}) + stub := fake.SetAccessTokenStub + fake.recordInvocation("SetAccessToken", []interface{}{arg1}) fake.setAccessTokenMutex.Unlock() - if fake.SetAccessTokenStub != nil { - fake.SetAccessTokenStub(token) + if stub != nil { + fake.SetAccessTokenStub(arg1) } } @@ -138,21 +167,29 @@ func (fake *FakeTokenCache) SetAccessTokenCallCount() int { return len(fake.setAccessTokenArgsForCall) } +func (fake *FakeTokenCache) SetAccessTokenCalls(stub func(string)) { + fake.setAccessTokenMutex.Lock() + defer fake.setAccessTokenMutex.Unlock() + fake.SetAccessTokenStub = stub +} + func (fake *FakeTokenCache) SetAccessTokenArgsForCall(i int) string { fake.setAccessTokenMutex.RLock() defer fake.setAccessTokenMutex.RUnlock() - return fake.setAccessTokenArgsForCall[i].token + argsForCall := fake.setAccessTokenArgsForCall[i] + return argsForCall.arg1 } -func (fake *FakeTokenCache) SetRefreshToken(token string) { +func (fake *FakeTokenCache) SetRefreshToken(arg1 string) { fake.setRefreshTokenMutex.Lock() fake.setRefreshTokenArgsForCall = append(fake.setRefreshTokenArgsForCall, struct { - token string - }{token}) - fake.recordInvocation("SetRefreshToken", []interface{}{token}) + arg1 string + }{arg1}) + stub := fake.SetRefreshTokenStub + fake.recordInvocation("SetRefreshToken", []interface{}{arg1}) fake.setRefreshTokenMutex.Unlock() - if fake.SetRefreshTokenStub != nil { - fake.SetRefreshTokenStub(token) + if stub != nil { + fake.SetRefreshTokenStub(arg1) } } @@ -162,10 +199,17 @@ func (fake *FakeTokenCache) SetRefreshTokenCallCount() int { return len(fake.setRefreshTokenArgsForCall) } +func (fake *FakeTokenCache) SetRefreshTokenCalls(stub func(string)) { + fake.setRefreshTokenMutex.Lock() + defer fake.setRefreshTokenMutex.Unlock() + fake.SetRefreshTokenStub = stub +} + func (fake *FakeTokenCache) SetRefreshTokenArgsForCall(i int) string { fake.setRefreshTokenMutex.RLock() defer fake.setRefreshTokenMutex.RUnlock() - return fake.setRefreshTokenArgsForCall[i].token + argsForCall := fake.setRefreshTokenArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeTokenCache) Invocations() map[string][][]interface{} { diff --git a/api/cfnetworking/wrapper/wrapperfakes/fake_uaaclient.go b/api/cfnetworking/wrapper/wrapperfakes/fake_uaaclient.go index 78b55e71eb5..01522737530 100644 --- a/api/cfnetworking/wrapper/wrapperfakes/fake_uaaclient.go +++ b/api/cfnetworking/wrapper/wrapperfakes/fake_uaaclient.go @@ -9,10 +9,10 @@ import ( ) type FakeUAAClient struct { - RefreshAccessTokenStub func(refreshToken string) (uaa.RefreshedTokens, error) + RefreshAccessTokenStub func(string) (uaa.RefreshedTokens, error) refreshAccessTokenMutex sync.RWMutex refreshAccessTokenArgsForCall []struct { - refreshToken string + arg1 string } refreshAccessTokenReturns struct { result1 uaa.RefreshedTokens @@ -26,21 +26,23 @@ type FakeUAAClient struct { invocationsMutex sync.RWMutex } -func (fake *FakeUAAClient) RefreshAccessToken(refreshToken string) (uaa.RefreshedTokens, error) { +func (fake *FakeUAAClient) RefreshAccessToken(arg1 string) (uaa.RefreshedTokens, error) { fake.refreshAccessTokenMutex.Lock() ret, specificReturn := fake.refreshAccessTokenReturnsOnCall[len(fake.refreshAccessTokenArgsForCall)] fake.refreshAccessTokenArgsForCall = append(fake.refreshAccessTokenArgsForCall, struct { - refreshToken string - }{refreshToken}) - fake.recordInvocation("RefreshAccessToken", []interface{}{refreshToken}) + arg1 string + }{arg1}) + stub := fake.RefreshAccessTokenStub + fakeReturns := fake.refreshAccessTokenReturns + fake.recordInvocation("RefreshAccessToken", []interface{}{arg1}) fake.refreshAccessTokenMutex.Unlock() - if fake.RefreshAccessTokenStub != nil { - return fake.RefreshAccessTokenStub(refreshToken) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } - return fake.refreshAccessTokenReturns.result1, fake.refreshAccessTokenReturns.result2 + return fakeReturns.result1, fakeReturns.result2 } func (fake *FakeUAAClient) RefreshAccessTokenCallCount() int { @@ -49,13 +51,22 @@ func (fake *FakeUAAClient) RefreshAccessTokenCallCount() int { return len(fake.refreshAccessTokenArgsForCall) } +func (fake *FakeUAAClient) RefreshAccessTokenCalls(stub func(string) (uaa.RefreshedTokens, error)) { + fake.refreshAccessTokenMutex.Lock() + defer fake.refreshAccessTokenMutex.Unlock() + fake.RefreshAccessTokenStub = stub +} + func (fake *FakeUAAClient) RefreshAccessTokenArgsForCall(i int) string { fake.refreshAccessTokenMutex.RLock() defer fake.refreshAccessTokenMutex.RUnlock() - return fake.refreshAccessTokenArgsForCall[i].refreshToken + argsForCall := fake.refreshAccessTokenArgsForCall[i] + return argsForCall.arg1 } func (fake *FakeUAAClient) RefreshAccessTokenReturns(result1 uaa.RefreshedTokens, result2 error) { + fake.refreshAccessTokenMutex.Lock() + defer fake.refreshAccessTokenMutex.Unlock() fake.RefreshAccessTokenStub = nil fake.refreshAccessTokenReturns = struct { result1 uaa.RefreshedTokens @@ -64,6 +75,8 @@ func (fake *FakeUAAClient) RefreshAccessTokenReturns(result1 uaa.RefreshedTokens } func (fake *FakeUAAClient) RefreshAccessTokenReturnsOnCall(i int, result1 uaa.RefreshedTokens, result2 error) { + fake.refreshAccessTokenMutex.Lock() + defer fake.refreshAccessTokenMutex.Unlock() fake.RefreshAccessTokenStub = nil if fake.refreshAccessTokenReturnsOnCall == nil { fake.refreshAccessTokenReturnsOnCall = make(map[int]struct { diff --git a/command/v7/shared/new_clients_test.go b/command/v7/shared/new_clients_test.go index 0ba13a69be7..751d101039a 100644 --- a/command/v7/shared/new_clients_test.go +++ b/command/v7/shared/new_clients_test.go @@ -52,8 +52,8 @@ var _ = Describe("New Clients", func() { Expect(err).NotTo(HaveOccurred()) Expect(fakeConfig.TargetCallCount()).To(Equal(2)) - Expect(fakeConfig.DialTimeoutCallCount()).To(Equal(4)) - Expect(fakeConfig.SkipSSLValidationCallCount()).To(Equal(4)) + Expect(fakeConfig.DialTimeoutCallCount()).To(Equal(3)) + Expect(fakeConfig.SkipSSLValidationCallCount()).To(Equal(3)) }) })