Skip to content

Commit

Permalink
Refactor tests to not call teardown explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
armsnyder committed Dec 12, 2022
1 parent 4e7c141 commit 946a151
Show file tree
Hide file tree
Showing 109 changed files with 678 additions and 1,360 deletions.
24 changes: 8 additions & 16 deletions access_requests_test.go
Expand Up @@ -27,8 +27,7 @@ import (
)

func TestListProjectAccessRequests(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/access_requests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down Expand Up @@ -94,8 +93,7 @@ func TestListProjectAccessRequests(t *testing.T) {
}

func TestListGroupAccessRequests(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/access_requests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down Expand Up @@ -161,8 +159,7 @@ func TestListGroupAccessRequests(t *testing.T) {
}

func TestRequestProjectAccess(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/access_requests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
Expand Down Expand Up @@ -208,8 +205,7 @@ func TestRequestProjectAccess(t *testing.T) {
}

func TestRequestGroupAccess(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/access_requests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
Expand Down Expand Up @@ -255,8 +251,7 @@ func TestRequestGroupAccess(t *testing.T) {
}

func TestApproveProjectAccessRequest(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/access_requests/10/approve", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
Expand Down Expand Up @@ -315,8 +310,7 @@ func TestApproveProjectAccessRequest(t *testing.T) {
}

func TestApproveGroupAccessRequest(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/access_requests/10/approve", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
Expand Down Expand Up @@ -375,8 +369,7 @@ func TestApproveGroupAccessRequest(t *testing.T) {
}

func TestDenyProjectAccessRequest(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/access_requests/10", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
Expand All @@ -400,8 +393,7 @@ func TestDenyProjectAccessRequest(t *testing.T) {
}

func TestDenyGroupAccessRequest(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/access_requests/10", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
Expand Down
9 changes: 3 additions & 6 deletions applications_test.go
Expand Up @@ -24,8 +24,7 @@ import (
)

func TestCreateApplication(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/applications",
func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -56,8 +55,7 @@ func TestCreateApplication(t *testing.T) {
}

func TestListApplications(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/applications",
func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -84,8 +82,7 @@ func TestListApplications(t *testing.T) {
}

func TestDeleteApplication(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/applications/4",
func(w http.ResponseWriter, r *http.Request) {
Expand Down
21 changes: 7 additions & 14 deletions audit_events_test.go
Expand Up @@ -9,8 +9,7 @@ import (
)

func TestAuditEventsService_ListInstanceAuditEvents(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/audit_events", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down Expand Up @@ -63,8 +62,7 @@ func TestAuditEventsService_ListInstanceAuditEvents(t *testing.T) {
}

func TestAuditEventsService_ListInstanceAuditEvents_StatusNotFound(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/audit_events", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand All @@ -78,8 +76,7 @@ func TestAuditEventsService_ListInstanceAuditEvents_StatusNotFound(t *testing.T)
}

func TestAuditEventsService_GetInstanceAuditEvent(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/audit_events/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down Expand Up @@ -135,8 +132,7 @@ func TestAuditEventsService_GetInstanceAuditEvent(t *testing.T) {
}

func TestAuditEventsService_ListGroupAuditEvents(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/6/audit_events", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down Expand Up @@ -199,8 +195,7 @@ func TestAuditEventsService_ListGroupAuditEvents(t *testing.T) {
}

func TestAuditEventsService_GetGroupAuditEvent(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/6/audit_events/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down Expand Up @@ -261,8 +256,7 @@ func TestAuditEventsService_GetGroupAuditEvent(t *testing.T) {
}

func TestAuditEventsService_ListProjectAuditEvents(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/6/audit_events", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down Expand Up @@ -325,8 +319,7 @@ func TestAuditEventsService_ListProjectAuditEvents(t *testing.T) {
}

func TestAuditEventsService_GetProjectAuditEvent(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/6/audit_events/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
Expand Down
3 changes: 1 addition & 2 deletions avatar_test.go
Expand Up @@ -23,8 +23,7 @@ import (
)

func TestGetAvatar(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux, client := setup(t)

const url = "https://www.gravatar.com/avatar/10e6bf7bcf22c2f00a3ef684b4ada178"

Expand Down

0 comments on commit 946a151

Please sign in to comment.