chore: tests wip
Build Snapshot / build-snapshot (push) Has been cancelled
DevSkim / DevSkim (push) Has been cancelled

This commit is contained in:
jamesread
2025-08-19 17:29:40 +01:00
parent 3dd7aaff88
commit f46a02fced
6 changed files with 54 additions and 108 deletions
@@ -1,51 +1,6 @@
package httpservers
/*
The REST API actually has very few tests, as the "real" API behind OliveTin
is is implemented as a gRPC in /internal/grpc. The REST API therefore only
handles HTTP specific stuff like authentication cookies and JWT parsing.
*/
import (
"fmt"
"github.com/OliveTin/OliveTin/internal/cors"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"net"
"net/http"
"testing"
)
func setupTestingServer(mux *runtime.ServeMux, t *testing.T) *http.Server {
lis, err := net.Listen("tcp", ":1337")
if err != nil || lis == nil {
t.Errorf("Could not listen %v %v", err, lis)
return nil
}
srv := &http.Server{Handler: cors.AllowCors(mux)}
go startTestingServer(lis, srv, t)
return srv
}
func startTestingServer(lis net.Listener, srv *http.Server, t *testing.T) {
if srv == nil {
t.Errorf("srv is nil. Could not listen")
return
}
go func() {
if err := srv.Serve(lis); err != nil {
fmt.Printf("couldn't start server: %+v", err)
}
}()
}
func newReq(path string) (*http.Request, *http.Client) {
client := &http.Client{}
req, _ := http.NewRequest("GET", fmt.Sprintf("http://localhost:1337/%v", path), nil)
return req, client
}