44 "context"
55 "io/ioutil"
66 "net/http"
7- "net/http/httptest"
87 "testing"
98
109 "github.com/github/codeql-action-sync/internal/cachedirectory"
@@ -19,15 +18,6 @@ import (
1918const initialActionRepository = "./pull_test/codeql-action-initial.git"
2019const modifiedActionRepository = "./pull_test/codeql-action-modified.git"
2120
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-
3121func getTestPullService (t * testing.T , temporaryDirectory string , gitCloneURL string , githubURL string ) pullService {
3222 cacheDirectory := cachedirectory .NewCacheDirectory (temporaryDirectory )
3323 var githubDotComClient * github.Client
@@ -131,7 +121,7 @@ func TestFindRelevantReleases(t *testing.T) {
131121
132122func TestPullReleases (t * testing.T ) {
133123 temporaryDirectory := test .CreateTemporaryDirectory (t )
134- githubTestServer , githubURL := getTestGitHubServer (t )
124+ githubTestServer , githubURL := test . GetTestHTTPServer (t )
135125 githubTestServer .HandleFunc ("/api/v3/repos/github/codeql-action/releases/tags/some-codeql-version-on-main" , func (response http.ResponseWriter , request * http.Request ) {
136126 test .ServeHTTPResponseFromFile (t , 200 , "./pull_test/api/release-some-codeql-version-on-main.json" , response )
137127 })
@@ -158,7 +148,7 @@ func TestPullReleases(t *testing.T) {
158148 // If we pull again, we should only download assets where the size mismatches.
159149 err = ioutil .WriteFile (pullService .cacheDirectory .AssetPath ("some-codeql-version-on-v1-and-v2" , "codeql-bundle.tar.gz" ), []byte ("Some nonsense." ), 0644 )
160150 require .NoError (t , err )
161- githubTestServer , githubURL = getTestGitHubServer (t )
151+ githubTestServer , githubURL = test . GetTestHTTPServer (t )
162152 githubTestServer .HandleFunc ("/api/v3/repos/github/codeql-action/releases/tags/some-codeql-version-on-main" , func (response http.ResponseWriter , request * http.Request ) {
163153 test .ServeHTTPResponseFromFile (t , 200 , "./pull_test/api/release-some-codeql-version-on-main.json" , response )
164154 })
0 commit comments