| package dashboard |
|
|
| import ( |
| "net/http" |
| "net/http/httptest" |
| "testing" |
| "time" |
| ) |
|
|
| func TestNewDashboard(t *testing.T) { |
| d := NewDashboard(nil) |
| if d == nil { |
| t.Fatal("expected non-nil dashboard") |
| } |
| } |
|
|
| func TestDashboardBroadcastSystemEvent(t *testing.T) { |
| d := NewDashboard(nil) |
|
|
| |
| mux := http.NewServeMux() |
| d.RegisterHandlers(mux) |
|
|
| |
| |
| evt := SystemEvent{ |
| Type: "instance.started", |
| } |
| d.BroadcastSystemEvent(evt) |
| } |
|
|
| func TestDashboardSSEHandlerRegistration(t *testing.T) { |
| d := NewDashboard(nil) |
| mux := http.NewServeMux() |
| d.RegisterHandlers(mux) |
|
|
| |
| |
| |
| } |
|
|
| func TestDashboardShutdown(t *testing.T) { |
| d := NewDashboard(nil) |
| |
| d.Shutdown() |
| } |
|
|
| func TestDashboardSetInstanceLister(t *testing.T) { |
| d := NewDashboard(nil) |
| d.SetInstanceLister(nil) |
| |
| } |
|
|
| func TestDashboardCacheHeaders(t *testing.T) { |
| d := NewDashboard(nil) |
|
|
| |
| handler := d.withLongCache(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| w.WriteHeader(200) |
| })) |
|
|
| req := httptest.NewRequest("GET", "/assets/app.js", nil) |
| w := httptest.NewRecorder() |
| handler.ServeHTTP(w, req) |
|
|
| cacheControl := w.Header().Get("Cache-Control") |
| if cacheControl != "public, max-age=31536000, immutable" { |
| t.Errorf("expected long cache header, got %q", cacheControl) |
| } |
|
|
| |
| handler = d.withNoCache(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| w.WriteHeader(200) |
| })) |
|
|
| req = httptest.NewRequest("GET", "/dashboard", nil) |
| w = httptest.NewRecorder() |
| handler.ServeHTTP(w, req) |
|
|
| cacheControl = w.Header().Get("Cache-Control") |
| if cacheControl != "no-store" { |
| t.Errorf("expected no-store cache header, got %q", cacheControl) |
| } |
| } |
|
|
| func TestDashboardShutdownTimeout(t *testing.T) { |
| d := NewDashboard(&DashboardConfig{ |
| IdleTimeout: 10 * time.Millisecond, |
| DisconnectTimeout: 20 * time.Millisecond, |
| ReaperInterval: 5 * time.Millisecond, |
| SSEBufferSize: 8, |
| }) |
|
|
| d.Shutdown() |
| time.Sleep(50 * time.Millisecond) |
| } |
|
|