Browse Source

cleanup tests (no substantive chnages)

use temporary variable to prevent mismatch between tests and resulting
error messages.
Will Norris 13 years ago
parent
commit
8c2a5ff206
4 changed files with 68 additions and 67 deletions
  1. +6
    -6
      github/github_test.go
  2. +44
    -44
      github/orgs_test.go
  3. +10
    -9
      github/repos_test.go
  4. +8
    -8
      github/users_test.go

+ 6
- 6
github/github_test.go View File

@ -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}}`)
})


+ 44
- 44
github/orgs_test.go View File

@ -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)
}
})


+ 10
- 9
github/repos_test.go View File

@ -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"}}`)
})


+ 8
- 8
github/users_test.go View File

@ -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")


Loading…
Cancel
Save