Reduce the amount of content served from files in tests. · github/codeql-action-sync-tool@a4a08e2 · GitHub
Skip to content

Commit a4a08e2

Browse files
committed
Reduce the amount of content served from files in tests.
1 parent e732b0c commit a4a08e2

9 files changed

Lines changed: 52 additions & 59 deletions

internal/pull/pull_test.go

Lines changed: 39 additions & 11 deletions

internal/pull/pull_test/api/asset-some-codeql-version-on-main.bin

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/pull/pull_test/api/asset-some-codeql-version-on-v1-and-v2.bin

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/pull/pull_test/api/release-some-codeql-version-on-main.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

internal/pull/pull_test/api/release-some-codeql-version-on-v1-and-v2.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

internal/push/push_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ func TestCreateRepositoryWhenUserIsOwner(t *testing.T) {
4444
githubTestServer, githubEnterpriseURL := test.GetTestHTTPServer(t)
4545
pushService := getTestPushService(t, temporaryDirectory, githubEnterpriseURL)
4646
githubTestServer.HandleFunc("/api/v3/user", func(response http.ResponseWriter, request *http.Request) {
47-
test.ServeHTTPResponseFromFile(t, http.StatusOK, "./push_test/api/user-is-owner.json", response)
47+
test.ServeHTTPResponseFromObject(t, github.User{Login: github.String("destination-repository-owner")}, response)
4848
}).Methods("GET")
4949
githubTestServer.HandleFunc("/api/v3/repos/destination-repository-owner/destination-repository-name", func(response http.ResponseWriter, request *http.Request) {
5050
response.WriteHeader(http.StatusNotFound)
5151
}).Methods("GET")
5252
githubTestServer.HandleFunc("/api/v3/user/repos", func(response http.ResponseWriter, request *http.Request) {
53-
response.Write([]byte("{}"))
53+
test.ServeHTTPResponseFromObject(t, github.Repository{}, response)
5454
}).Methods("POST")
5555
_, err := pushService.createRepository()
5656
require.NoError(t, err)
@@ -61,13 +61,13 @@ func TestUpdateRepositoryWhenUserIsOwner(t *testing.T) {
6161
githubTestServer, githubEnterpriseURL := test.GetTestHTTPServer(t)
6262
pushService := getTestPushService(t, temporaryDirectory, githubEnterpriseURL)
6363
githubTestServer.HandleFunc("/api/v3/user", func(response http.ResponseWriter, request *http.Request) {
64-
test.ServeHTTPResponseFromFile(t, http.StatusOK, "./push_test/api/user-is-owner.json", response)
64+
test.ServeHTTPResponseFromObject(t, github.User{Login: github.String("destination-repository-owner")}, response)
6565
}).Methods("GET")
6666
githubTestServer.HandleFunc("/api/v3/repos/destination-repository-owner/destination-repository-name", func(response http.ResponseWriter, request *http.Request) {
6767
test.ServeHTTPResponseFromObject(t, github.Repository{Homepage: github.String(repositoryHomepage)}, response)
6868
}).Methods("GET")
6969
githubTestServer.HandleFunc("/api/v3/repos/destination-repository-owner/destination-repository-name", func(response http.ResponseWriter, request *http.Request) {
70-
response.Write([]byte("{}"))
70+
test.ServeHTTPResponseFromObject(t, github.Repository{}, response)
7171
}).Methods("PATCH")
7272
_, err := pushService.createRepository()
7373
require.NoError(t, err)
@@ -78,7 +78,7 @@ func TestUpdateRepositoryWhenUserIsOwnerForced(t *testing.T) {
7878
githubTestServer, githubEnterpriseURL := test.GetTestHTTPServer(t)
7979
pushService := getTestPushService(t, temporaryDirectory, githubEnterpriseURL)
8080
githubTestServer.HandleFunc("/api/v3/user", func(response http.ResponseWriter, request *http.Request) {
81-
test.ServeHTTPResponseFromFile(t, http.StatusOK, "./push_test/api/user-is-owner.json", response)
81+
test.ServeHTTPResponseFromObject(t, github.User{Login: github.String("destination-repository-owner")}, response)
8282
}).Methods("GET")
8383
githubTestServer.HandleFunc("/api/v3/repos/destination-repository-owner/destination-repository-name", func(response http.ResponseWriter, request *http.Request) {
8484
test.ServeHTTPResponseFromObject(t, github.Repository{}, response)
@@ -99,24 +99,24 @@ func TestCreateOrganizationAndRepositoryWhenOrganizationIsOwner(t *testing.T) {
9999
pushService := getTestPushService(t, temporaryDirectory, githubEnterpriseURL)
100100
organizationCreated := false
101101
githubTestServer.HandleFunc("/api/v3/user", func(response http.ResponseWriter, request *http.Request) {
102-
test.ServeHTTPResponseFromFile(t, http.StatusOK, "./push_test/api/user-is-not-owner.json", response)
102+
test.ServeHTTPResponseFromObject(t, github.User{Login: github.String("user")}, response)
103103
}).Methods("GET")
104104
githubTestServer.HandleFunc("/api/v3/orgs/destination-repository-owner", func(response http.ResponseWriter, request *http.Request) {
105105
if organizationCreated {
106-
response.Write([]byte("{}"))
106+
test.ServeHTTPResponseFromObject(t, github.Organization{}, response)
107107
} else {
108108
response.WriteHeader(http.StatusNotFound)
109109
}
110110
}).Methods("GET")
111111
githubTestServer.HandleFunc("/api/v3/admin/organizations", func(response http.ResponseWriter, request *http.Request) {
112-
response.Write([]byte("{}"))
112+
test.ServeHTTPResponseFromObject(t, github.Organization{}, response)
113113
organizationCreated = true
114114
}).Methods("POST")
115115
githubTestServer.HandleFunc("/api/v3/repos/destination-repository-owner/destination-repository-name", func(response http.ResponseWriter, request *http.Request) {
116116
response.WriteHeader(http.StatusNotFound)
117117
}).Methods("GET")
118118
githubTestServer.HandleFunc("/api/v3/orgs/destination-repository-owner/repos", func(response http.ResponseWriter, request *http.Request) {
119-
response.Write([]byte("{}"))
119+
test.ServeHTTPResponseFromObject(t, github.Repository{}, response)
120120
}).Methods("POST")
121121
_, err := pushService.createRepository()
122122
require.NoError(t, err)

internal/push/push_test/api/user-is-not-owner.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

internal/push/push_test/api/user-is-owner.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/test.go

Lines changed: 4 additions & 9 deletions

0 commit comments

Comments
 (0)