Skip to content

Commit

Permalink
Remove unnecessary mocking from tests
Browse files Browse the repository at this point in the history
- Info is an unprotected endpoint and would never really return a 401
  • Loading branch information
sneal committed Aug 10, 2022
1 parent 72c7998 commit 6dbe61f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
20 changes: 10 additions & 10 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = Describe("Api", func() {

Describe("Test get stemcells", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/stemcells", stemcells, ""}, "basic")
setupMockRoute(MockRoute{"GET", "/stemcells", stemcells, ""}, "basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand All @@ -39,7 +39,7 @@ var _ = Describe("Api", func() {

Describe("Test get releases", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/releases", releases, ""}, "basic")
setupMockRoute(MockRoute{"GET", "/releases", releases, ""}, "basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand Down Expand Up @@ -68,7 +68,7 @@ var _ = Describe("Api", func() {
Describe("Test deployments", func() {
Describe("get deployments", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/deployments", deployments, ""}, "basic")
setupMockRoute(MockRoute{"GET", "/deployments", deployments, ""}, "basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand Down Expand Up @@ -96,7 +96,7 @@ var _ = Describe("Api", func() {

Describe("create deployments", func() {
BeforeEach(func() {
setup(MockRoute{"POST", "/deployments", deploymentTask, ""}, "basic")
setupMockRoute(MockRoute{"POST", "/deployments", deploymentTask, ""}, "basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand All @@ -120,7 +120,7 @@ var _ = Describe("Api", func() {

Describe("Test tasks", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/tasks", tasks, ""}, "basic")
setupMockRoute(MockRoute{"GET", "/tasks", tasks, ""}, "basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand All @@ -145,7 +145,7 @@ var _ = Describe("Api", func() {

Describe("Test tasks by query", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/tasks", tasks, ""}, "basic")
setupMockRoute(MockRoute{"GET", "/tasks", tasks, ""}, "basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand All @@ -172,7 +172,7 @@ var _ = Describe("Api", func() {

Describe("Test get deployment manifest", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/deployments/foo", manifest, ""}, "basic")
setupMockRoute(MockRoute{"GET", "/deployments/foo", manifest, ""}, "basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand All @@ -195,7 +195,7 @@ var _ = Describe("Api", func() {

Describe("Test get deployment vms", func() {
BeforeEach(func() {
setupMultiple([]MockRoute{
setupMockRoutes([]MockRoute{
{"GET", "/deployments/foo/vms", "", server.URL + "/tasks/2"},
{"GET", "/tasks/2", task, ""},
{"GET", "/tasks/2", task, ""},
Expand Down Expand Up @@ -255,7 +255,7 @@ var _ = Describe("Api", func() {

Describe("Test stop instance", func() {
BeforeEach(func() {
setupMultiple([]MockRoute{
setupMockRoutes([]MockRoute{
{"PUT", "/deployments/deployment-foo/jobs/job-foo/id-foo", "", server.URL + "/tasks/3"},
{"GET", "/tasks/3", task3, ""},
{"GET", "/tasks/3", task3, ""},
Expand Down Expand Up @@ -283,7 +283,7 @@ var _ = Describe("Api", func() {

Describe("Test stop instance no converge", func() {
BeforeEach(func() {
setupMultiple([]MockRoute{
setupMockRoutes([]MockRoute{
{"PUT", "/deployments/deployment-foo/instance_groups/job-foo/id-foo/actions/stopped", "", server.URL + "/tasks/3"},
{"GET", "/tasks/3", task3, ""},
{"GET", "/tasks/3", task3, ""},
Expand Down
10 changes: 7 additions & 3 deletions bosh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ type MockRoute struct {
Redirect string
}

func setup(mock MockRoute, authType string) {
setupMultiple([]MockRoute{mock}, authType)
func setup(authType string) {
setupMockRoute(MockRoute{}, authType)
}

func setupMultiple(mockEndpoints []MockRoute, authType string) {
func setupMockRoute(mock MockRoute, authType string) {
setupMockRoutes([]MockRoute{mock}, authType)
}

func setupMockRoutes(mockEndpoints []MockRoute, authType string) {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
fakeUAAServer = FakeUAAServer()
Expand Down
10 changes: 5 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Client", func() {
var client *Client

BeforeEach(func() {
setup(MockRoute{"GET", "/stemcells", `{}`, ""}, "basic")
setup("basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand Down Expand Up @@ -52,7 +52,7 @@ var _ = Describe("Client", func() {
var client *Client

BeforeEach(func() {
setup(MockRoute{"GET", "/stemcells", `{}`, ""}, "uaa")
setup("uaa")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand Down Expand Up @@ -83,7 +83,7 @@ var _ = Describe("Client", func() {

Context("when the refresh token has expired", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/stemcells", `{}`, ""}, "uaa")
setupMockRoute(MockRoute{"GET", "/stemcells", `[]`, ""}, "uaa")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand All @@ -101,7 +101,7 @@ var _ = Describe("Client", func() {
token, err := client.GetToken()
Expect(err).Should(BeNil())
Expect(token).Should(Equal("bearer foobar2"))
_, err = client.GetInfo()
_, err = client.GetStemcells()
Expect(err).Should(BeNil())
token, err = client.GetToken()
Expect(err).Should(BeNil())
Expand All @@ -123,7 +123,7 @@ var _ = Describe("Client", func() {

Context("when the refresh token is valid", func() {
BeforeEach(func() {
setup(MockRoute{"GET", "/stemcells", `{}`, ""}, "uaa")
setup("uaa")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Expand Down

0 comments on commit 6dbe61f

Please sign in to comment.