Files
beacon-server/internal/api/handlers/info_test.go
MrAlders0n 9bbf8efee5 release: v2.0.4 (#217)
* perf(routes): batch cross-IATA and hash route search (#216)

One search fired a /routes/cross request per IATA pair (138k on 2026-10-08). Route search now takes an optional iatas list and runs a fixed number of index-backed queries. /info advertises built-in minimum client versions.

* chore: bump version to 2.0.4
2026-10-09 22:17:23 -04:00

40 lines
1.1 KiB
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package handlers
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/MeshCore-Beacon/beacon-server/internal/api"
)
func TestGetInfo(t *testing.T) {
version, web := "0.1.1", "2.0.3"
for _, tc := range []struct {
name string
info api.Info
want string
}{
{"unset", api.Info{ServerVersion: "2.0.2"}, `{"minAppVersion":null,"minWebVersion":null,"serverVersion":"2.0.2"}`},
{"set", api.Info{MinAppVersion: &version, MinWebVersion: &web, ServerVersion: "2.0.2"}, `{"minAppVersion":"0.1.1","minWebVersion":"2.0.3","serverVersion":"2.0.2"}`},
} {
t.Run(tc.name, func(t *testing.T) {
w := httptest.NewRecorder()
InfoRouter(tc.info).ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/", nil))
if w.Code != http.StatusOK {
t.Fatalf("expected 200, got %d", w.Code)
}
if got := w.Header().Get("Cache-Control"); got != "no-cache" {
t.Fatalf("Cache-Control = %q, want no-cache", got)
}
if got := strings.TrimSpace(w.Body.String()); got != tc.want {
t.Fatalf("body = %s, want %s", got, tc.want)
}
})
}
}