package hammerhead import ( "os" "regexp" "testing" ) // Every address the dashboard JavaScript navigates to must be served by the server, or a // reload on that page would 404. func TestDashboardPathsMatchThePage(t *testing.T) { src, err := os.ReadFile("web/index.html") if err != nil { t.Fatal(err) } m := regexp.MustCompile(`TAB_PATH = \{([^}]*)\}`).FindSubmatch(src) if m == nil { t.Fatal("TAB_PATH not found in web/index.html") } paths := regexp.MustCompile(`'(/[a-z/-]+)'`).FindAllSubmatch(m[1], -1) if len(paths) < 10 { t.Fatalf("found only %d page paths", len(paths)) } for _, p := range paths { if !isDashboardPath(string(p[1])) { t.Errorf("%s is a dashboard page but the server doesn't serve it", p[1]) } } for _, p := range []string{"/api/me", "/nope", "/server", "/server/nope"} { if isDashboardPath(p) { t.Errorf("%s should not serve the dashboard", p) } } }