Fix bad import rebase artifacts

This commit is contained in:
Jan-Eric Hellenberg
2021-05-10 12:08:02 +02:00
committed by Jan-Eric Hellenberg
parent 13052fa021
commit e45cd92557
5 changed files with 17 additions and 18 deletions

View File

@ -3,7 +3,7 @@ package api
import (
"github.com/gorilla/mux"
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/auth"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
"gitlab.hpi.de/codeocean/codemoon/poseidon/logging"
"net/http"
)
@ -21,7 +21,7 @@ const (
// always returns a router for the newest version of our API. We
// use gorilla/mux because it is more convenient than net/http, e.g.
// when extracting path parameters.
func NewRouter(runnerPool pool.RunnerPool) *mux.Router {
func NewRouter(runnerPool environment.RunnerPool) *mux.Router {
router := mux.NewRouter()
// this can later be restricted to a specific host with
// `router.Host(...)` and to HTTPS with `router.Schemes("https")`
@ -32,7 +32,7 @@ func NewRouter(runnerPool pool.RunnerPool) *mux.Router {
// newRouterV1 returns a sub-router containing the routes of version
// 1 of our API.
func newRouterV1(router *mux.Router, runnerPool pool.RunnerPool) *mux.Router {
func newRouterV1(router *mux.Router, runnerPool environment.RunnerPool) *mux.Router {
v1 := router.PathPrefix(RouteBase).Subrouter()
v1.HandleFunc(RouteHealth, Health).Methods(http.MethodGet)

View File

@ -4,7 +4,7 @@ import (
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
"gitlab.hpi.de/codeocean/codemoon/poseidon/config"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
"net/http"
"net/http/httptest"
"testing"
@ -17,7 +17,7 @@ func mockHTTPHandler(writer http.ResponseWriter, _ *http.Request) {
func TestNewRouterV1WithAuthenticationDisabled(t *testing.T) {
config.Config.Server.Token = ""
router := mux.NewRouter()
v1 := newRouterV1(router, pool.NewLocalRunnerPool())
v1 := newRouterV1(router, environment.NewLocalRunnerPool())
t.Run("health route is accessible", func(t *testing.T) {
request, err := http.NewRequest(http.MethodGet, "/api/v1/health", nil)
@ -44,7 +44,7 @@ func TestNewRouterV1WithAuthenticationDisabled(t *testing.T) {
func TestNewRouterV1WithAuthenticationEnabled(t *testing.T) {
config.Config.Server.Token = "TestToken"
router := mux.NewRouter()
v1 := newRouterV1(router, pool.NewLocalRunnerPool())
v1 := newRouterV1(router, environment.NewLocalRunnerPool())
t.Run("health route is accessible", func(t *testing.T) {
request, err := http.NewRequest(http.MethodGet, "/api/v1/health", nil)

View File

@ -7,7 +7,6 @@ import (
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
"gitlab.hpi.de/codeocean/codemoon/poseidon/config"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
"gitlab.hpi.de/codeocean/codemoon/poseidon/runner"
"net/http"
"net/url"
@ -95,24 +94,24 @@ func connectToRunner(writer http.ResponseWriter, request *http.Request) {
// The findRunnerMiddleware looks up the runnerId for routes containing it
// and adds the runner to the context of the request.
func findRunnerMiddleware(runnerPool pool.RunnerPool) func(handler http.Handler) http.Handler {
func findRunnerMiddleware(runnerPool environment.RunnerPool) func(handler http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
// Find runner
runnerId := mux.Vars(request)[RunnerIdKey]
r, ok := runnerPool.GetRunner(runnerId)
r, ok := runnerPool.Get(runnerId)
if !ok {
writer.WriteHeader(http.StatusNotFound)
return
}
ctx := runner.NewContext(request.Context(), r)
ctx := runner.NewContext(request.Context(), r.(runner.Runner))
requestWithRunner := request.WithContext(ctx)
next.ServeHTTP(writer, requestWithRunner)
})
}
}
func registerRunnerRoutes(router *mux.Router, runnerPool pool.RunnerPool) {
func registerRunnerRoutes(router *mux.Router, runnerPool environment.RunnerPool) {
router.HandleFunc("", provideRunner).Methods(http.MethodPost)
runnerRouter := router.PathPrefix(fmt.Sprintf("/{%s}", RunnerIdKey)).Subrouter()
runnerRouter.Use(findRunnerMiddleware(runnerPool))

View File

@ -7,7 +7,7 @@ import (
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
"gitlab.hpi.de/codeocean/codemoon/poseidon/runner"
"net/http"
"net/http/httptest"
@ -17,10 +17,10 @@ import (
)
func TestFindRunnerMiddleware(t *testing.T) {
runnerPool := pool.NewLocalRunnerPool()
runnerPool := environment.NewLocalRunnerPool()
var capturedRunner runner.Runner
testRunner := runner.NewExerciseRunner("testRunner")
runnerPool.AddRunner(testRunner)
runnerPool.Add(testRunner)
testRunnerIdRoute := func(writer http.ResponseWriter, request *http.Request) {
var ok bool
@ -66,10 +66,10 @@ func TestFindRunnerMiddleware(t *testing.T) {
}
func TestExecuteRoute(t *testing.T) {
runnerPool := pool.NewLocalRunnerPool()
runnerPool := environment.NewLocalRunnerPool()
router := NewRouter(runnerPool)
testRunner := runner.NewExerciseRunner("testRunner")
runnerPool.AddRunner(testRunner)
runnerPool.Add(testRunner)
path, err := router.Get(ExecutePath).URL(RunnerIdKey, testRunner.Id())
if err != nil {