From 8c2a5ff206de9993c53dfb4c09e780560dd63f23 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 28 May 2013 22:09:48 -0700 Subject: [PATCH] cleanup tests (no substantive chnages) use temporary variable to prevent mismatch between tests and resulting error messages. --- github/github_test.go | 12 +++--- github/orgs_test.go | 88 +++++++++++++++++++++---------------------- github/repos_test.go | 19 +++++----- github/users_test.go | 16 ++++---- 4 files changed, 68 insertions(+), 67 deletions(-) diff --git a/github/github_test.go b/github/github_test.go index 5cc5518..d3e66d1 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -119,8 +119,8 @@ func TestDo(t *testing.T) { } mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `{"A":"a"}`) }) @@ -176,7 +176,7 @@ func TestDo_redirectLoop(t *testing.T) { func TestCheckResponse(t *testing.T) { res := &http.Response{ Request: &http.Request{}, - StatusCode: 400, + StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(strings.NewReader(`{"message":"m", "errors": [{"resource": "r", "field": "f", "code": "c"}]}`)), } @@ -201,7 +201,7 @@ func TestCheckResponse(t *testing.T) { func TestCheckResponse_noBody(t *testing.T) { res := &http.Response{ Request: &http.Request{}, - StatusCode: 400, + StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(strings.NewReader("")), } err := CheckResponse(res).(*ErrorResponse) @@ -238,8 +238,8 @@ func TestRateLimit(t *testing.T) { defer teardown() mux.HandleFunc("/rate_limit", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `{"rate":{"limit":2,"remaining":1}}`) }) diff --git a/github/orgs_test.go b/github/orgs_test.go index dbe20bc..425e512 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -20,8 +20,8 @@ func TestOrganizationsService_List_authenticatedUser(t *testing.T) { defer teardown() mux.HandleFunc("/user/orgs", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `[{"id":1},{"id":2}]`) }) @@ -43,8 +43,8 @@ func TestOrganizationsService_List_specifiedUser(t *testing.T) { mux.HandleFunc("/users/u/orgs", func(w http.ResponseWriter, r *http.Request) { var v string - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `[{"id":1},{"id":2}]`) if v = r.FormValue("page"); v != "2" { @@ -79,8 +79,8 @@ func TestOrganizationsService_Get(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `{"id":1, "login":"l", "url":"u", "avatar_url": "a", "location":"l"}`) }) @@ -116,8 +116,8 @@ func TestOrganizationsService_Edit(t *testing.T) { v := new(Organization) json.NewDecoder(r.Body).Decode(v) - if r.Method != "PATCH" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "PATCH"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) @@ -152,8 +152,8 @@ func TestOrganizationsService_ListMembers(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/members", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `[{"id":1}]`) }) @@ -184,8 +184,8 @@ func TestOrganizationsService_ListPublicMembers(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/public_members", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `[{"id":1}]`) }) @@ -216,8 +216,8 @@ func TestOrganizationsService_CheckMembership(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) @@ -237,8 +237,8 @@ func TestOrganizationsService_CheckMembership_notMember(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } w.WriteHeader(http.StatusNotFound) }) @@ -260,8 +260,8 @@ func TestOrganizationsService_CheckMembership_error(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } http.Error(w, "BadRequest", http.StatusBadRequest) }) @@ -291,8 +291,8 @@ func TestOrganizationsService_CheckPublicMembership(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) @@ -312,8 +312,8 @@ func TestOrganizationsService_CheckPublicMembership_notMember(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } w.WriteHeader(http.StatusNotFound) }) @@ -335,8 +335,8 @@ func TestOrganizationsService_CheckPublicMembership_error(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } http.Error(w, "BadRequest", http.StatusBadRequest) }) @@ -366,8 +366,8 @@ func TestOrganizationsService_RemoveMember(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "DELETE" { - t.Errorf("Request method = %v, want %v", r.Method, "DELETE") + if m := "DELETE"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) @@ -392,8 +392,8 @@ func TestOrganizationsService_ListTeams(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `[{"id":1}]`) }) @@ -424,8 +424,8 @@ func TestOrganizationsService_GetTeam(t *testing.T) { defer teardown() mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `{"id":1, "name":"n", "url":"u", "slug": "s", "permission":"p"}`) }) @@ -451,8 +451,8 @@ func TestOrganizationsService_CreateTeam(t *testing.T) { v := new(Team) json.NewDecoder(r.Body).Decode(v) - if r.Method != "POST" { - t.Errorf("Request method = %v, want %v", r.Method, "POST") + if m := "POST"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) @@ -492,8 +492,8 @@ func TestOrganizationsService_EditTeam(t *testing.T) { v := new(Team) json.NewDecoder(r.Body).Decode(v) - if r.Method != "PATCH" { - t.Errorf("Request method = %v, want %v", r.Method, "PATCH") + if m := "PATCH"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) @@ -518,8 +518,8 @@ func TestOrganizationsService_DeleteTeam(t *testing.T) { defer teardown() mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "DELETE" { - t.Errorf("Request method = %v, want %v", r.Method, "DELETE") + if m := "DELETE"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) @@ -534,8 +534,8 @@ func TestOrganizationsService_AddTeamMember(t *testing.T) { defer teardown() mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "PUT"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) @@ -560,8 +560,8 @@ func TestOrganizationsService_RemoveTeamMember(t *testing.T) { defer teardown() mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "DELETE" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "DELETE"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) @@ -586,8 +586,8 @@ func TestOrganizationsService_PublicizeMembership(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "PUT"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) @@ -612,8 +612,8 @@ func TestOrganizationsService_ConcealMembership(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "DELETE" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "DELETE"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } }) diff --git a/github/repos_test.go b/github/repos_test.go index f5e8a13..d7fdfea 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -19,8 +19,8 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) { defer teardown() mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `[{"id":1},{"id":2}]`) }) @@ -42,8 +42,8 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) { mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) { var v string - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } if v = r.FormValue("type"); v != "owner" { t.Errorf("Request type parameter = %v, want %v", v, "owner") @@ -88,10 +88,11 @@ func TestRepositoriesService_ListByOrg(t *testing.T) { defer teardown() mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + var v string + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } - v := r.FormValue("type") + v = r.FormValue("type") if v != "forks" { t.Errorf("Request type parameter = %v, want %v", v, "forks") } @@ -129,8 +130,8 @@ func TestRepositoriesService_Get(t *testing.T) { defer teardown() mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"}}`) }) diff --git a/github/users_test.go b/github/users_test.go index b3836fc..087d523 100644 --- a/github/users_test.go +++ b/github/users_test.go @@ -20,8 +20,8 @@ func TestUsersService_Get_authenticatedUser(t *testing.T) { defer teardown() mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `{"id":1}`) }) @@ -42,8 +42,8 @@ func TestUsersService_Get_specifiedUser(t *testing.T) { defer teardown() mux.HandleFunc("/users/u", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } fmt.Fprint(w, `{"id":1}`) }) @@ -79,8 +79,8 @@ func TestUsersService_Edit(t *testing.T) { v := new(User) json.NewDecoder(r.Body).Decode(v) - if r.Method != "PATCH" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "PATCH"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) @@ -106,8 +106,8 @@ func TestUsersService_List(t *testing.T) { mux.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) { var v string - if r.Method != "GET" { - t.Errorf("Request method = %v, want %v", r.Method, "GET") + if m := "GET"; m != r.Method { + t.Errorf("Request method = %v, want %v", r.Method, m) } if v = r.FormValue("since"); v != "1" { t.Errorf("Request since parameter = %v, want %v", v, "1")