support for organization runners

This commit is contained in:
Reinier Timmer
2020-04-23 16:36:40 +02:00
parent d1429beaa6
commit fb35dd4131
12 changed files with 236 additions and 61 deletions

View File

@@ -31,6 +31,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, h.Body)
}
// NewServer creates a fake server for running unit tests
func NewServer() *httptest.Server {
routes := map[string]handler{
// For CreateRegistrationToken
@@ -46,6 +47,18 @@ func NewServer() *httptest.Server {
Status: http.StatusBadRequest,
Body: "",
},
"/orgs/test/actions/runners/registration-token": handler{
Status: http.StatusCreated,
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
},
"/orgs/invalid/actions/runners/registration-token": handler{
Status: http.StatusOK,
Body: fmt.Sprintf("{\"token\": \"%s\", \"expires_at\": \"%s\"}", RegistrationToken, time.Now().Add(time.Hour*1).Format(time.RFC3339)),
},
"/orgs/error/actions/runners/registration-token": handler{
Status: http.StatusBadRequest,
Body: "",
},
// For ListRunners
"/repos/test/valid/actions/runners": handler{
@@ -60,6 +73,18 @@ func NewServer() *httptest.Server {
Status: http.StatusBadRequest,
Body: "",
},
"/orgs/test/actions/runners": handler{
Status: http.StatusOK,
Body: RunnersListBody,
},
"/orgs/invalid/actions/runners": handler{
Status: http.StatusNoContent,
Body: "",
},
"/orgs/error/actions/runners": handler{
Status: http.StatusBadRequest,
Body: "",
},
// For RemoveRunner
"/repos/test/valid/actions/runners/1": handler{
@@ -74,6 +99,18 @@ func NewServer() *httptest.Server {
Status: http.StatusBadRequest,
Body: "",
},
"/orgs/test/actions/runners/1": handler{
Status: http.StatusNoContent,
Body: "",
},
"/orgs/invalid/actions/runners/1": handler{
Status: http.StatusOK,
Body: "",
},
"/orgs/error/actions/runners/1": handler{
Status: http.StatusBadRequest,
Body: "",
},
}
mux := http.NewServeMux()