diff --git a/go-concourse/concourse/internal/connection.go b/go-concourse/concourse/internal/connection.go index d19a209802f..d4426d8ef85 100644 --- a/go-concourse/concourse/internal/connection.go +++ b/go-concourse/concourse/internal/connection.go @@ -16,10 +16,6 @@ import ( "github.com/vito/go-sse/sse" ) -//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate - -//counterfeiter:generate . Connection - // Deprecated. Use HTTPAgent instead type Connection interface { URL() string diff --git a/go-concourse/concourse/internal/connection_test.go b/go-concourse/concourse/internal/connection_test.go index 99b395ed3dd..bc6aa083683 100644 --- a/go-concourse/concourse/internal/connection_test.go +++ b/go-concourse/concourse/internal/connection_test.go @@ -25,7 +25,6 @@ var _ = Describe("ATC Connection", func() { atcServer *ghttp.Server connection Connection - agent HTTPAgent tracing bool ) @@ -34,7 +33,6 @@ var _ = Describe("ATC Connection", func() { atcServer = ghttp.NewServer() connection = NewConnection(atcServer.URL(), nil, tracing) - agent = NewHTTPAgent(atcServer.URL(), nil, tracing) }) Describe("#Send", func() { @@ -353,34 +351,6 @@ var _ = Describe("ATC Connection", func() { }) }) - Describe("403 response", func() { - BeforeEach(func() { - atcServer = ghttp.NewServer() - - agent = NewHTTPAgent(atcServer.URL(), nil, tracing) - - atcServer.AppendHandlers( - ghttp.CombineHandlers( - ghttp.VerifyRequest("DELETE", "/api/v1/teams/main/pipelines/foo"), - ghttp.RespondWith(http.StatusForbidden, "problem"), - ), - ) - }) - - It("returns back 403", func() { - resp, err := agent.Send(Request{ - RequestName: atc.DeletePipeline, - Params: rata.Params{ - "pipeline_name": "foo", - "team_name": atc.DefaultTeamName, - }, - }) - - Expect(resp.StatusCode).To(Equal(http.StatusForbidden)) - Expect(err).ToNot(HaveOccurred()) - }) - }) - Describe("404 response", func() { Context("when the response does not contain JSONAPI errors", func() { BeforeEach(func() { diff --git a/go-concourse/concourse/internal/http_agent_test.go b/go-concourse/concourse/internal/http_agent_test.go new file mode 100644 index 00000000000..d4daeee58cf --- /dev/null +++ b/go-concourse/concourse/internal/http_agent_test.go @@ -0,0 +1,57 @@ +package internal_test + +import ( + "net/http" + + "github.com/concourse/concourse/atc" + . "github.com/concourse/concourse/go-concourse/concourse/internal" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/ghttp" + "github.com/tedsuo/rata" +) + +var _ = Describe("HTTPAgent Client", func() { + var ( + atcServer *ghttp.Server + + agent HTTPAgent + + tracing bool + ) + + BeforeEach(func() { + atcServer = ghttp.NewServer() + + agent = NewHTTPAgent(atcServer.URL(), nil, tracing) + }) + + Describe("#Send", func() { + Describe("Different status codes", func() { + Describe("403 response", func() { + BeforeEach(func() { + atcServer = ghttp.NewServer() + + agent = NewHTTPAgent(atcServer.URL(), nil, tracing) + atcServer.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest("DELETE", "/api/v1/teams/main/pipelines/foo"), + ghttp.RespondWith(http.StatusForbidden, "problem"), + ), + ) + }) + It("returns back 403", func() { + resp, err := agent.Send(Request{ + RequestName: atc.DeletePipeline, + Params: rata.Params{ + "pipeline_name": "foo", + "team_name": atc.DefaultTeamName, + }, + }) + Expect(resp.StatusCode).To(Equal(http.StatusForbidden)) + Expect(err).ToNot(HaveOccurred()) + }) + }) + }) + }) +}) diff --git a/go-concourse/concourse/internal/internalfakes/fake_connection.go b/go-concourse/concourse/internal/internalfakes/fake_connection.go deleted file mode 100644 index 791c8e85d76..00000000000 --- a/go-concourse/concourse/internal/internalfakes/fake_connection.go +++ /dev/null @@ -1,402 +0,0 @@ -// Code generated by counterfeiter. DO NOT EDIT. -package internalfakes - -import ( - "net/http" - "sync" - - "github.com/concourse/concourse/go-concourse/concourse/internal" - "github.com/vito/go-sse/sse" -) - -type FakeConnection struct { - ConnectToEventStreamStub func(internal.Request) (*sse.EventSource, error) - connectToEventStreamMutex sync.RWMutex - connectToEventStreamArgsForCall []struct { - arg1 internal.Request - } - connectToEventStreamReturns struct { - result1 *sse.EventSource - result2 error - } - connectToEventStreamReturnsOnCall map[int]struct { - result1 *sse.EventSource - result2 error - } - HTTPClientStub func() *http.Client - hTTPClientMutex sync.RWMutex - hTTPClientArgsForCall []struct { - } - hTTPClientReturns struct { - result1 *http.Client - } - hTTPClientReturnsOnCall map[int]struct { - result1 *http.Client - } - SendStub func(internal.Request, *internal.Response) error - sendMutex sync.RWMutex - sendArgsForCall []struct { - arg1 internal.Request - arg2 *internal.Response - } - sendReturns struct { - result1 error - } - sendReturnsOnCall map[int]struct { - result1 error - } - SendHTTPRequestStub func(*http.Request, bool, *internal.Response) error - sendHTTPRequestMutex sync.RWMutex - sendHTTPRequestArgsForCall []struct { - arg1 *http.Request - arg2 bool - arg3 *internal.Response - } - sendHTTPRequestReturns struct { - result1 error - } - sendHTTPRequestReturnsOnCall map[int]struct { - result1 error - } - URLStub func() string - uRLMutex sync.RWMutex - uRLArgsForCall []struct { - } - uRLReturns struct { - result1 string - } - uRLReturnsOnCall map[int]struct { - result1 string - } - invocations map[string][][]interface{} - invocationsMutex sync.RWMutex -} - -func (fake *FakeConnection) ConnectToEventStream(arg1 internal.Request) (*sse.EventSource, error) { - fake.connectToEventStreamMutex.Lock() - ret, specificReturn := fake.connectToEventStreamReturnsOnCall[len(fake.connectToEventStreamArgsForCall)] - fake.connectToEventStreamArgsForCall = append(fake.connectToEventStreamArgsForCall, struct { - arg1 internal.Request - }{arg1}) - stub := fake.ConnectToEventStreamStub - fakeReturns := fake.connectToEventStreamReturns - fake.recordInvocation("ConnectToEventStream", []interface{}{arg1}) - fake.connectToEventStreamMutex.Unlock() - if stub != nil { - return stub(arg1) - } - if specificReturn { - return ret.result1, ret.result2 - } - return fakeReturns.result1, fakeReturns.result2 -} - -func (fake *FakeConnection) ConnectToEventStreamCallCount() int { - fake.connectToEventStreamMutex.RLock() - defer fake.connectToEventStreamMutex.RUnlock() - return len(fake.connectToEventStreamArgsForCall) -} - -func (fake *FakeConnection) ConnectToEventStreamCalls(stub func(internal.Request) (*sse.EventSource, error)) { - fake.connectToEventStreamMutex.Lock() - defer fake.connectToEventStreamMutex.Unlock() - fake.ConnectToEventStreamStub = stub -} - -func (fake *FakeConnection) ConnectToEventStreamArgsForCall(i int) internal.Request { - fake.connectToEventStreamMutex.RLock() - defer fake.connectToEventStreamMutex.RUnlock() - argsForCall := fake.connectToEventStreamArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakeConnection) ConnectToEventStreamReturns(result1 *sse.EventSource, result2 error) { - fake.connectToEventStreamMutex.Lock() - defer fake.connectToEventStreamMutex.Unlock() - fake.ConnectToEventStreamStub = nil - fake.connectToEventStreamReturns = struct { - result1 *sse.EventSource - result2 error - }{result1, result2} -} - -func (fake *FakeConnection) ConnectToEventStreamReturnsOnCall(i int, result1 *sse.EventSource, result2 error) { - fake.connectToEventStreamMutex.Lock() - defer fake.connectToEventStreamMutex.Unlock() - fake.ConnectToEventStreamStub = nil - if fake.connectToEventStreamReturnsOnCall == nil { - fake.connectToEventStreamReturnsOnCall = make(map[int]struct { - result1 *sse.EventSource - result2 error - }) - } - fake.connectToEventStreamReturnsOnCall[i] = struct { - result1 *sse.EventSource - result2 error - }{result1, result2} -} - -func (fake *FakeConnection) HTTPClient() *http.Client { - fake.hTTPClientMutex.Lock() - ret, specificReturn := fake.hTTPClientReturnsOnCall[len(fake.hTTPClientArgsForCall)] - fake.hTTPClientArgsForCall = append(fake.hTTPClientArgsForCall, struct { - }{}) - stub := fake.HTTPClientStub - fakeReturns := fake.hTTPClientReturns - fake.recordInvocation("HTTPClient", []interface{}{}) - fake.hTTPClientMutex.Unlock() - if stub != nil { - return stub() - } - if specificReturn { - return ret.result1 - } - return fakeReturns.result1 -} - -func (fake *FakeConnection) HTTPClientCallCount() int { - fake.hTTPClientMutex.RLock() - defer fake.hTTPClientMutex.RUnlock() - return len(fake.hTTPClientArgsForCall) -} - -func (fake *FakeConnection) HTTPClientCalls(stub func() *http.Client) { - fake.hTTPClientMutex.Lock() - defer fake.hTTPClientMutex.Unlock() - fake.HTTPClientStub = stub -} - -func (fake *FakeConnection) HTTPClientReturns(result1 *http.Client) { - fake.hTTPClientMutex.Lock() - defer fake.hTTPClientMutex.Unlock() - fake.HTTPClientStub = nil - fake.hTTPClientReturns = struct { - result1 *http.Client - }{result1} -} - -func (fake *FakeConnection) HTTPClientReturnsOnCall(i int, result1 *http.Client) { - fake.hTTPClientMutex.Lock() - defer fake.hTTPClientMutex.Unlock() - fake.HTTPClientStub = nil - if fake.hTTPClientReturnsOnCall == nil { - fake.hTTPClientReturnsOnCall = make(map[int]struct { - result1 *http.Client - }) - } - fake.hTTPClientReturnsOnCall[i] = struct { - result1 *http.Client - }{result1} -} - -func (fake *FakeConnection) Send(arg1 internal.Request, arg2 *internal.Response) error { - fake.sendMutex.Lock() - ret, specificReturn := fake.sendReturnsOnCall[len(fake.sendArgsForCall)] - fake.sendArgsForCall = append(fake.sendArgsForCall, struct { - arg1 internal.Request - arg2 *internal.Response - }{arg1, arg2}) - stub := fake.SendStub - fakeReturns := fake.sendReturns - fake.recordInvocation("Send", []interface{}{arg1, arg2}) - fake.sendMutex.Unlock() - if stub != nil { - return stub(arg1, arg2) - } - if specificReturn { - return ret.result1 - } - return fakeReturns.result1 -} - -func (fake *FakeConnection) SendCallCount() int { - fake.sendMutex.RLock() - defer fake.sendMutex.RUnlock() - return len(fake.sendArgsForCall) -} - -func (fake *FakeConnection) SendCalls(stub func(internal.Request, *internal.Response) error) { - fake.sendMutex.Lock() - defer fake.sendMutex.Unlock() - fake.SendStub = stub -} - -func (fake *FakeConnection) SendArgsForCall(i int) (internal.Request, *internal.Response) { - fake.sendMutex.RLock() - defer fake.sendMutex.RUnlock() - argsForCall := fake.sendArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2 -} - -func (fake *FakeConnection) SendReturns(result1 error) { - fake.sendMutex.Lock() - defer fake.sendMutex.Unlock() - fake.SendStub = nil - fake.sendReturns = struct { - result1 error - }{result1} -} - -func (fake *FakeConnection) SendReturnsOnCall(i int, result1 error) { - fake.sendMutex.Lock() - defer fake.sendMutex.Unlock() - fake.SendStub = nil - if fake.sendReturnsOnCall == nil { - fake.sendReturnsOnCall = make(map[int]struct { - result1 error - }) - } - fake.sendReturnsOnCall[i] = struct { - result1 error - }{result1} -} - -func (fake *FakeConnection) SendHTTPRequest(arg1 *http.Request, arg2 bool, arg3 *internal.Response) error { - fake.sendHTTPRequestMutex.Lock() - ret, specificReturn := fake.sendHTTPRequestReturnsOnCall[len(fake.sendHTTPRequestArgsForCall)] - fake.sendHTTPRequestArgsForCall = append(fake.sendHTTPRequestArgsForCall, struct { - arg1 *http.Request - arg2 bool - arg3 *internal.Response - }{arg1, arg2, arg3}) - stub := fake.SendHTTPRequestStub - fakeReturns := fake.sendHTTPRequestReturns - fake.recordInvocation("SendHTTPRequest", []interface{}{arg1, arg2, arg3}) - fake.sendHTTPRequestMutex.Unlock() - if stub != nil { - return stub(arg1, arg2, arg3) - } - if specificReturn { - return ret.result1 - } - return fakeReturns.result1 -} - -func (fake *FakeConnection) SendHTTPRequestCallCount() int { - fake.sendHTTPRequestMutex.RLock() - defer fake.sendHTTPRequestMutex.RUnlock() - return len(fake.sendHTTPRequestArgsForCall) -} - -func (fake *FakeConnection) SendHTTPRequestCalls(stub func(*http.Request, bool, *internal.Response) error) { - fake.sendHTTPRequestMutex.Lock() - defer fake.sendHTTPRequestMutex.Unlock() - fake.SendHTTPRequestStub = stub -} - -func (fake *FakeConnection) SendHTTPRequestArgsForCall(i int) (*http.Request, bool, *internal.Response) { - fake.sendHTTPRequestMutex.RLock() - defer fake.sendHTTPRequestMutex.RUnlock() - argsForCall := fake.sendHTTPRequestArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 -} - -func (fake *FakeConnection) SendHTTPRequestReturns(result1 error) { - fake.sendHTTPRequestMutex.Lock() - defer fake.sendHTTPRequestMutex.Unlock() - fake.SendHTTPRequestStub = nil - fake.sendHTTPRequestReturns = struct { - result1 error - }{result1} -} - -func (fake *FakeConnection) SendHTTPRequestReturnsOnCall(i int, result1 error) { - fake.sendHTTPRequestMutex.Lock() - defer fake.sendHTTPRequestMutex.Unlock() - fake.SendHTTPRequestStub = nil - if fake.sendHTTPRequestReturnsOnCall == nil { - fake.sendHTTPRequestReturnsOnCall = make(map[int]struct { - result1 error - }) - } - fake.sendHTTPRequestReturnsOnCall[i] = struct { - result1 error - }{result1} -} - -func (fake *FakeConnection) URL() string { - fake.uRLMutex.Lock() - ret, specificReturn := fake.uRLReturnsOnCall[len(fake.uRLArgsForCall)] - fake.uRLArgsForCall = append(fake.uRLArgsForCall, struct { - }{}) - stub := fake.URLStub - fakeReturns := fake.uRLReturns - fake.recordInvocation("URL", []interface{}{}) - fake.uRLMutex.Unlock() - if stub != nil { - return stub() - } - if specificReturn { - return ret.result1 - } - return fakeReturns.result1 -} - -func (fake *FakeConnection) URLCallCount() int { - fake.uRLMutex.RLock() - defer fake.uRLMutex.RUnlock() - return len(fake.uRLArgsForCall) -} - -func (fake *FakeConnection) URLCalls(stub func() string) { - fake.uRLMutex.Lock() - defer fake.uRLMutex.Unlock() - fake.URLStub = stub -} - -func (fake *FakeConnection) URLReturns(result1 string) { - fake.uRLMutex.Lock() - defer fake.uRLMutex.Unlock() - fake.URLStub = nil - fake.uRLReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeConnection) URLReturnsOnCall(i int, result1 string) { - fake.uRLMutex.Lock() - defer fake.uRLMutex.Unlock() - fake.URLStub = nil - if fake.uRLReturnsOnCall == nil { - fake.uRLReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.uRLReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeConnection) Invocations() map[string][][]interface{} { - fake.invocationsMutex.RLock() - defer fake.invocationsMutex.RUnlock() - fake.connectToEventStreamMutex.RLock() - defer fake.connectToEventStreamMutex.RUnlock() - fake.hTTPClientMutex.RLock() - defer fake.hTTPClientMutex.RUnlock() - fake.sendMutex.RLock() - defer fake.sendMutex.RUnlock() - fake.sendHTTPRequestMutex.RLock() - defer fake.sendHTTPRequestMutex.RUnlock() - fake.uRLMutex.RLock() - defer fake.uRLMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} - for key, value := range fake.invocations { - copiedInvocations[key] = value - } - return copiedInvocations -} - -func (fake *FakeConnection) recordInvocation(key string, args []interface{}) { - fake.invocationsMutex.Lock() - defer fake.invocationsMutex.Unlock() - if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} - } - if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} - } - fake.invocations[key] = append(fake.invocations[key], args) -} - -var _ internal.Connection = new(FakeConnection)