test: add unit tests

This commit is contained in:
rramiachraf 2024-03-06 20:53:29 +01:00
parent c8747c0182
commit afc0347a1b
19 changed files with 358 additions and 31 deletions

25
main.go
View file

@ -1,7 +1,6 @@
package main
import (
"context"
"fmt"
"net"
"net/http"
@ -9,35 +8,15 @@ import (
"strconv"
"time"
"github.com/a-h/templ"
"github.com/gorilla/mux"
"github.com/rramiachraf/dumb/handlers"
"github.com/rramiachraf/dumb/views"
"github.com/sirupsen/logrus"
)
var logger = logrus.New()
func main() {
r := mux.NewRouter()
r.Use(handlers.MustHeaders)
r.Handle("/", templ.Handler(views.HomePage()))
r.HandleFunc("/{id}-lyrics", handlers.Lyrics(logger)).Methods("GET")
r.HandleFunc("/albums/{artist}/{albumName}", handlers.Album(logger)).Methods("GET")
r.HandleFunc("/images/{filename}.{ext}", handlers.ImageProxy(logger)).Methods("GET")
r.HandleFunc("/search", handlers.Search(logger)).Methods("GET")
r.HandleFunc("/{id}/{artist-song}/{verse}/annotations", handlers.Annotations(logger)).Methods("GET")
r.HandleFunc("/instances.json", handlers.Instances(logger)).Methods("GET")
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
views.ErrorPage(404, "page not found").Render(context.Background(), w)
})
var logger = logrus.New()
server := &http.Server{
Handler: r,
Handler: handlers.New(logger),
WriteTimeout: 25 * time.Second,
ReadTimeout: 25 * time.Second,
}