Skip to content

Commit f926e16

Browse files
test: use constants for test sha
1 parent d1bf722 commit f926e16

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pkg/provider/github_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ var (
5050
tagType = "tag"
5151
)
5252

53+
var testSHA = "deadbeef"
54+
5355
func createGithubRef(ref string) *github.Reference {
54-
sha := "deadbeef"
55-
return &github.Reference{Ref: &ref, Object: &github.GitObject{SHA: &sha, Type: &commitType}}
56+
return &github.Reference{Ref: &ref, Object: &github.GitObject{SHA: &testSHA, Type: &commitType}}
5657
}
5758

5859
func createGithubRefWithTag(ref, sha string) *github.Reference {
@@ -143,7 +144,7 @@ func githubHandler(w http.ResponseWriter, r *http.Request) {
143144
var data map[string]string
144145
json.NewDecoder(r.Body).Decode(&data)
145146
r.Body.Close()
146-
if data["sha"] != "deadbeef" || data["ref"] != "refs/tags/v2.0.0" {
147+
if data["sha"] != testSHA || data["ref"] != "refs/tags/v2.0.0" {
147148
http.Error(w, "invalid sha or ref", http.StatusBadRequest)
148149
return
149150
}
@@ -162,7 +163,7 @@ func githubHandler(w http.ResponseWriter, r *http.Request) {
162163
return
163164
}
164165
if r.Method == http.MethodGet && r.URL.Path == "/repos/owner/test-repo/git/tags/12345678" {
165-
sha := "deadbeef"
166+
sha := testSHA
166167
json.NewEncoder(w).Encode(github.Tag{
167168
Object: &github.GitObject{SHA: &sha, Type: &commitType},
168169
})
@@ -233,11 +234,11 @@ func TestGithubGetReleases(t *testing.T) {
233234
expectedSHA string
234235
expectedVersion string
235236
}{
236-
{"", "", "deadbeef", "2020.4.19"},
237-
{"", "^v[0-9]*", "deadbeef", "2.0.0"},
238-
{"2-beta", "", "deadbeef", "2.1.0-beta"},
239-
{"3-beta", "", "deadbeef", "3.0.0-beta.2"},
240-
{"4-beta", "", "deadbeef", "4.0.0-beta"},
237+
{"", "", testSHA, "2020.4.19"},
238+
{"", "^v[0-9]*", testSHA, "2.0.0"},
239+
{"2-beta", "", testSHA, "2.1.0-beta"},
240+
{"3-beta", "", testSHA, "3.0.0-beta.2"},
241+
{"4-beta", "", testSHA, "4.0.0-beta"},
241242
}
242243

243244
for _, tc := range testCases {
@@ -255,6 +256,6 @@ func TestGithubGetReleases(t *testing.T) {
255256
func TestGithubCreateRelease(t *testing.T) {
256257
repo, ts := getNewGithubTestRepo(t)
257258
defer ts.Close()
258-
err := repo.CreateRelease(&provider.CreateReleaseConfig{NewVersion: "2.0.0", SHA: "deadbeef"})
259+
err := repo.CreateRelease(&provider.CreateReleaseConfig{NewVersion: "2.0.0", SHA: testSHA})
259260
require.NoError(t, err)
260261
}

0 commit comments

Comments
 (0)