func TestExercise_Find(t *testing.T) { user := mockUser() initUser(user) exercise := mockExercise() initExercise(exercise) _, err := models.FindExerciseByID(dbConn(), exercise.Id) if err != nil { t.Fatalf("Exercise was not found in the Database oO?") } }
func exercisify(inner func(http.ResponseWriter, *http.Request, *sitrep.UsersByEmail, *sitrep.ExerciseByIdentifier), h *Handler, requireAuthentication bool) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { exerciseIDRaw, err := parseExerciseID(r) if err != nil { makeForbidden(w, err) return } exerciseID, err := gocql.ParseUUID(exerciseIDRaw) if err != nil { makeForbidden(w, err) return } exercise, err := models.FindExerciseByID(h.Cassandra, exerciseID) if err != nil { makeForbidden(w, err) return } if !requireAuthentication { inner(w, r, nil, exercise) return } counter := metrics.GetOrRegisterCounter(statAuthFail, h.statMap) accessToken, err := parseCredentials(r) if err != nil { counter.Inc(1) makeForbidden(w, err) return } user, err := models.VerifyUserRequest(h.Cassandra, accessToken) if err != nil { counter.Inc(1) makeForbidden(w, err) return } inner(w, r, user, exercise) }) }
func exercisifyOnly(inner func(http.ResponseWriter, *http.Request, *sitrep.ExerciseByIdentifier), h *Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { exerciseIDRaw, err := parseExerciseID(r) if err != nil { makeForbidden(w, err) return } exerciseID, err := gocql.ParseUUID(exerciseIDRaw) if err != nil { makeForbidden(w, err) return } exercise, err := models.FindExerciseByID(h.Cassandra, exerciseID) if err != nil { makeForbidden(w, err) return } inner(w, r, exercise) }) }