4
4
"context"
5
5
"io/ioutil"
6
6
"net/http"
7
- "net/http/httptest"
8
7
"testing"
9
8
10
9
"github.com/github/codeql-action-sync/internal/cachedirectory"
@@ -19,15 +18,6 @@ import (
19
18
const initialActionRepository = "./pull_test/codeql-action-initial.git"
20
19
const modifiedActionRepository = "./pull_test/codeql-action-modified.git"
21
20
22
- func getTestGitHubServer (t * testing.T ) (* http.ServeMux , string ) {
23
- mux := http .NewServeMux ()
24
- server := httptest .NewServer (mux )
25
- t .Cleanup (func () {
26
- server .Close ()
27
- })
28
- return mux , server .URL
29
- }
30
-
31
21
func getTestPullService (t * testing.T , temporaryDirectory string , gitCloneURL string , githubURL string ) pullService {
32
22
cacheDirectory := cachedirectory .NewCacheDirectory (temporaryDirectory )
33
23
var githubDotComClient * github.Client
@@ -131,7 +121,7 @@ func TestFindRelevantReleases(t *testing.T) {
131
121
132
122
func TestPullReleases (t * testing.T ) {
133
123
temporaryDirectory := test .CreateTemporaryDirectory (t )
134
- githubTestServer , githubURL := getTestGitHubServer (t )
124
+ githubTestServer , githubURL := test . GetTestHTTPServer (t )
135
125
githubTestServer .HandleFunc ("/api/v3/repos/github/codeql-action/releases/tags/some-codeql-version-on-main" , func (response http.ResponseWriter , request * http.Request ) {
136
126
test .ServeHTTPResponseFromFile (t , 200 , "./pull_test/api/release-some-codeql-version-on-main.json" , response )
137
127
})
@@ -158,7 +148,7 @@ func TestPullReleases(t *testing.T) {
158
148
// If we pull again, we should only download assets where the size mismatches.
159
149
err = ioutil .WriteFile (pullService .cacheDirectory .AssetPath ("some-codeql-version-on-v1-and-v2" , "codeql-bundle.tar.gz" ), []byte ("Some nonsense." ), 0644 )
160
150
require .NoError (t , err )
161
- githubTestServer , githubURL = getTestGitHubServer (t )
151
+ githubTestServer , githubURL = test . GetTestHTTPServer (t )
162
152
githubTestServer .HandleFunc ("/api/v3/repos/github/codeql-action/releases/tags/some-codeql-version-on-main" , func (response http.ResponseWriter , request * http.Request ) {
163
153
test .ServeHTTPResponseFromFile (t , 200 , "./pull_test/api/release-some-codeql-version-on-main.json" , response )
164
154
})
0 commit comments