From dd991518f38d334b58f242c8750a0f098f8c99a6 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 20 Feb 2019 20:55:48 +0530 Subject: [PATCH 1/3] Added test case for commit ref with percent encoding --- github/repos_commits_test.go | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/github/repos_commits_test.go b/github/repos_commits_test.go index 2cbcc5ae5f7..35896210aa3 100644 --- a/github/repos_commits_test.go +++ b/github/repos_commits_test.go @@ -223,6 +223,47 @@ func TestRepositoriesService_GetCommitSHA1(t *testing.T) { } } +func TestRepositoriesService_NonAlphabetCharacter_GetCommitSHA1(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + const sha1 = "01234abcde" + + mux.HandleFunc("/repos/o/r/commits/master%20hash", 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", "master%20hash", "") + if err != nil { + t.Errorf("Repositories.GetCommitSHA1 returned error: %v", err) + } + + want := sha1 + if 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") + } + + want = "" + if got != want { + t.Errorf("Repositories.GetCommitSHA1 = %v, want %v", got, want) + } +} + func TestRepositoriesService_CompareCommits(t *testing.T) { client, mux, _, teardown := setup() defer teardown() From 11d4853019c0c1805a6c576955a927f605da8bf9 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Sat, 23 Feb 2019 19:04:15 +0530 Subject: [PATCH 2/3] Improved structure of code --- github/repos_commits_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/github/repos_commits_test.go b/github/repos_commits_test.go index 35896210aa3..56bf4e62963 100644 --- a/github/repos_commits_test.go +++ b/github/repos_commits_test.go @@ -240,8 +240,7 @@ func TestRepositoriesService_NonAlphabetCharacter_GetCommitSHA1(t *testing.T) { t.Errorf("Repositories.GetCommitSHA1 returned error: %v", err) } - want := sha1 - if got != want { + if want := sha1; got != want { t.Errorf("Repositories.GetCommitSHA1 = %v, want %v", got, want) } @@ -258,8 +257,7 @@ func TestRepositoriesService_NonAlphabetCharacter_GetCommitSHA1(t *testing.T) { t.Errorf("Expected HTTP 304 response") } - want = "" - if got != want { + if want = ""; got != want { t.Errorf("Repositories.GetCommitSHA1 = %v, want %v", got, want) } } From 6d0990097f9d8b3041eaf534be71423c53608a4c Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Sat, 23 Feb 2019 21:52:54 +0530 Subject: [PATCH 3/3] Improved structure of code --- github/repos_commits_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos_commits_test.go b/github/repos_commits_test.go index 56bf4e62963..e076febb5a4 100644 --- a/github/repos_commits_test.go +++ b/github/repos_commits_test.go @@ -257,7 +257,7 @@ func TestRepositoriesService_NonAlphabetCharacter_GetCommitSHA1(t *testing.T) { t.Errorf("Expected HTTP 304 response") } - if want = ""; got != want { + if want := ""; got != want { t.Errorf("Repositories.GetCommitSHA1 = %v, want %v", got, want) } }