skyview/internal/server/server_test.go
Ole-Morten Duesund 8ce4f4c397 Initial implementation of SkyView - ADS-B aircraft tracker
- Go application with embedded static files for dump1090 frontend
- TCP client for SBS-1/BaseStation format (port 30003)
- Real-time WebSocket updates with aircraft tracking
- Modern web frontend with Leaflet maps and mobile-responsive design
- Aircraft table with filtering/sorting and statistics dashboard
- Origin configuration for receiver location and distance calculations
- Automatic config.json loading from current directory
- Foreground execution by default with optional -daemon flag

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 22:09:37 +02:00

55 lines
No EOL
1 KiB
Go

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)
}
}