diff --git a/internal/fake/http.go b/internal/fake/http.go index cef1c67..b0feab2 100644 --- a/internal/fake/http.go +++ b/internal/fake/http.go @@ -25,12 +25,12 @@ type route struct { fn httpFunc } -func routeTable() []*route { +func fetchRoute() []*route { return []*route{ { - method: "DELETE", - file: "", - fn: handleNoContent, + method: "GET", + file: "../../../testdata/get-repo.json", + fn: handleSuccess, regexp: regexp.MustCompile( fmt.Sprintf( "^%s%s$", @@ -38,6 +38,22 @@ func routeTable() []*route { `/repos/([^/]+)/([^/]+)`, )), }, + { + file: "../../testdata/commit-diff.json", + fn: handleSuccess, + method: "GET", + regexp: regexp.MustCompile( + fmt.Sprintf( + "^%s%s$", + baseURLPath, + `/repos/([^/]+)/([^/]+)/compare/\w+\.\.\.\w+`, + )), + }, + } +} + +func postRoute() []*route { + return []*route{ { method: "PATCH", file: "../../../testdata/edit-repo.json", @@ -60,10 +76,15 @@ func routeTable() []*route { `/repos/([^/]+)/([^/]+)/forks`, )), }, + } +} + +func delRoute() []*route { + return []*route{ { - method: "GET", - file: "../../../testdata/get-repo.json", - fn: handleSuccess, + method: "DELETE", + file: "", + fn: handleNoContent, regexp: regexp.MustCompile( fmt.Sprintf( "^%s%s$", @@ -71,20 +92,16 @@ func routeTable() []*route { `/repos/([^/]+)/([^/]+)`, )), }, - { - file: "../../testdata/commit-diff.json", - fn: handleSuccess, - method: "GET", - regexp: regexp.MustCompile( - fmt.Sprintf( - "^%s%s$", - baseURLPath, - `/repos/([^/]+)/([^/]+)/compare/\w+\.\.\.\w+`, - )), - }, } } +func routeTable() []*route { + var route []*route + route = append(route, fetchRoute()...) + route = append(route, postRoute()...) + return append(route, delRoute()...) +} + func handleNoContent(file string, w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) if _, err := fmt.Fprint(w, file); err != nil {