mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-22 00:22:25 +00:00
* chore: add .github/CODEOWNERS for main branch policy Signed-off-by: MrAlders0n <MrAlders0n@smal.ca> * chore: add .github/workflows/main-source-guard.yml for main branch policy Signed-off-by: MrAlders0n <MrAlders0n@smal.ca> * feat(meshmapper): authenticate API imports (#211) * feat(observers): add traffic-sorted directory (#212) * fix(observers): rank available traffic over rolling seven days * chore: bump version to 2.1.0 * chore: set release version to 2.0.2 * feat(api): add /info with mobile min app version (#214) * chore: bump version to 2.0.3 --------- Signed-off-by: MrAlders0n <MrAlders0n@smal.ca>
40 lines
1.0 KiB
Go
40 lines
1.0 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 := "0.1.1"
|
|
for _, tc := range []struct {
|
|
name string
|
|
info api.Info
|
|
want string
|
|
}{
|
|
{"unset", api.Info{ServerVersion: "2.0.2"}, `{"minAppVersion":null,"serverVersion":"2.0.2"}`},
|
|
{"set", api.Info{MinAppVersion: &version, ServerVersion: "2.0.2"}, `{"minAppVersion":"0.1.1","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)
|
|
}
|
|
})
|
|
}
|
|
}
|