Skip to content

Commit

Permalink
Merge pull request #800 from Pix4D/pci-3852-client-split-tests
Browse files Browse the repository at this point in the history
go-concourse: split tests based on the client type used
  • Loading branch information
aliculPix4D authored Oct 4, 2024
2 parents b418082 + 7bc2c11 commit 0d5c826
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 436 deletions.
4 changes: 0 additions & 4 deletions go-concourse/concourse/internal/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 0 additions & 30 deletions go-concourse/concourse/internal/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var _ = Describe("ATC Connection", func() {
atcServer *ghttp.Server

connection Connection
agent HTTPAgent

tracing bool
)
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
57 changes: 57 additions & 0 deletions go-concourse/concourse/internal/http_agent_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})
})
})
})
Loading

0 comments on commit 0d5c826

Please sign in to comment.