Skip to content

Commit

Permalink
add test for traling %
Browse files Browse the repository at this point in the history
as given in the original google#1099
  • Loading branch information
vetinari committed Feb 18, 2020
1 parent 3f35727 commit 3f85498
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions github/repos_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,45 @@ func TestRepositoriesService_NonAlphabetCharacter_GetCommitSHA1(t *testing.T) {
}
}

func TestRepositoriesService_TrailingPercent_GetCommitSHA1(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
const sha1 = "01234abcde"

mux.HandleFunc("/repos/o/r/commits/comm%", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeV3SHA)

fmt.Fprintf(w, sha1)
})

got, _, err := client.Repositories.GetCommitSHA1(context.Background(), "o", "r", "comm%", "")
if err != nil {
t.Errorf("Repositories.GetCommitSHA1 returned error: %v", err)
}

if want := sha1; got != want {
t.Errorf("Repositories.GetCommitSHA1 = %v, want %v", got, want)
}

mux.HandleFunc("/repos/o/r/commits/tag", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeV3SHA)
testHeader(t, r, "If-None-Match", `"`+sha1+`"`)

w.WriteHeader(http.StatusNotModified)
})

got, _, err = client.Repositories.GetCommitSHA1(context.Background(), "o", "r", "tag", sha1)
if err == nil {
t.Errorf("Expected HTTP 304 response")
}

if want := ""; got != want {
t.Errorf("Repositories.GetCommitSHA1 = %v, want %v", got, want)
}
}

func TestRepositoriesService_CompareCommits(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down

0 comments on commit 3f85498

Please sign in to comment.