2020-09-27 20:40:07 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestViewerPageGET(t *testing.T) {
|
2020-09-28 15:36:40 +00:00
|
|
|
// Load templates
|
|
|
|
if err := loadTemplates(); err != nil {
|
|
|
|
t.Errorf("Failed to load templates: %v", err)
|
|
|
|
}
|
|
|
|
|
2020-10-03 11:28:54 +00:00
|
|
|
cfg = &Options{}
|
|
|
|
|
2020-09-28 15:36:40 +00:00
|
|
|
// Test GET request
|
|
|
|
r, _ := http.NewRequest("GET", "/", nil)
|
2020-09-27 20:40:07 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
http.HandlerFunc(viewerHandler).ServeHTTP(w, r)
|
|
|
|
if w.Code != http.StatusOK {
|
2020-09-28 15:36:40 +00:00
|
|
|
t.Errorf("Viewer page returned %v != %v on GET", w.Code, http.StatusOK)
|
2020-09-27 20:40:07 +00:00
|
|
|
}
|
2020-09-30 14:09:25 +00:00
|
|
|
|
|
|
|
// Test GET request on not found page
|
|
|
|
r, _ = http.NewRequest("GET", "", nil)
|
|
|
|
w = httptest.NewRecorder()
|
|
|
|
http.HandlerFunc(viewerHandler).ServeHTTP(w, r)
|
|
|
|
if w.Code != http.StatusNotFound {
|
|
|
|
t.Errorf("Viewer page returned %v != %v on GET", w.Code, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test GET request on statistics page
|
2020-10-06 07:32:41 +00:00
|
|
|
r, _ = http.NewRequest("GET", "/_stats/demo/", nil)
|
2020-09-30 14:09:25 +00:00
|
|
|
w = httptest.NewRecorder()
|
|
|
|
http.HandlerFunc(statisticsHandler).ServeHTTP(w, r)
|
|
|
|
if w.Code != http.StatusOK {
|
|
|
|
t.Errorf("Viewer page returned %v != %v on GET", w.Code, http.StatusOK)
|
|
|
|
}
|
2020-09-27 20:40:07 +00:00
|
|
|
}
|