Add tests for runners execute route

Co-authored-by: Tobias Kantusch <tobias.kantusch@student.hpi.uni-potsdam.de>
This commit is contained in:
Konrad Hanff
2021-04-30 16:23:00 +02:00
parent 6a00ea3165
commit 612bc55bdd
10 changed files with 300 additions and 90 deletions

View File

@@ -7,6 +7,7 @@ import (
)
type Status string
type ContextKey string
const (
StatusReady Status = "ready"
@@ -15,7 +16,7 @@ const (
StatusFinished Status = "finished"
// runnerContextKey is the key used to store runners in context.Context
runnerContextKey = "runner"
runnerContextKey ContextKey = "runner"
)
type Runner interface {
@@ -74,11 +75,11 @@ func (r *ExerciseRunner) Id() string {
return r.id
}
func NewContext(ctx context.Context, runner *Runner) context.Context {
func NewContext(ctx context.Context, runner Runner) context.Context {
return context.WithValue(ctx, runnerContextKey, runner)
}
func FromContext(ctx context.Context) (*Runner, bool) {
runner, ok := ctx.Value(runnerContextKey).(*Runner)
func FromContext(ctx context.Context) (Runner, bool) {
runner, ok := ctx.Value(runnerContextKey).(Runner)
return runner, ok
}