skyview/internal/server/server_test.go

55 lines
1 KiB
Go
Raw Normal View History

package server
import (
"embed"
"net/http"
"net/http/httptest"
"testing"
"skyview/internal/config"
)
//go:embed testdata/*
var testStaticFiles embed.FS
func TestNew(t *testing.T) {
cfg := &config.Config{
Server: config.ServerConfig{
Address: ":8080",
Port: 8080,
},
Dump1090: config.Dump1090Config{
Host: "localhost",
Port: 8080,
URL: "http://localhost:8080",
},
}
handler := New(cfg, testStaticFiles)
if handler == nil {
t.Fatal("Expected handler to be created")
}
}
func TestCORSHeaders(t *testing.T) {
cfg := &config.Config{
Dump1090: config.Dump1090Config{
URL: "http://localhost:8080",
},
}
handler := New(cfg, testStaticFiles)
req := httptest.NewRequest("OPTIONS", "/api/aircraft", nil)
w := httptest.NewRecorder()
handler.ServeHTTP(w, req)
if w.Header().Get("Access-Control-Allow-Origin") != "*" {
t.Errorf("Expected CORS header, got %s", w.Header().Get("Access-Control-Allow-Origin"))
}
if w.Code != http.StatusOK {
t.Errorf("Expected status 200, got %d", w.Code)
}
}