Files
beacon-server/internal/api/info_test.go
T

53 lines
1.4 KiB
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package api
import (
"regexp"
"testing"
)
func TestHigherVersion(t *testing.T) {
for _, tc := range []struct{ a, b, want string }{
{"", "", ""},
{"2.0.3", "", "2.0.3"},
{"", "2.0.3", "2.0.3"},
{"2.0.3", "2.0.10", "2.0.10"},
{"2.1.0", "2.0.9", "2.1.0"},
{"10.0.0", "9.9.9", "10.0.0"},
{"2.0.3", "2.0.3", "2.0.3"},
} {
if got := HigherVersion(tc.a, tc.b); got != tc.want {
t.Errorf("HigherVersion(%q, %q) = %q, want %q", tc.a, tc.b, got, tc.want)
}
}
}
// Clients reject anything but plain X.Y.Z, so a typo here would lock them all out.
func TestClientFloorsAreValid(t *testing.T) {
re := regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+$`)
for name, v := range map[string]string{"MinAppVersion": MinAppVersion, "MinWebVersion": MinWebVersion} {
if v != "" && !re.MatchString(v) {
t.Errorf("%s = %q, want X.Y.Z or empty", name, v)
}
}
}
func TestAppFloor(t *testing.T) {
for _, tc := range []struct {
configured string
requireOrigin bool
want string
}{
{"", false, MinAppVersion},
{"", true, TicketAppVersion},
{"9.0.0", true, "9.0.0"},
{"9.0.0", false, "9.0.0"},
} {
if got := AppFloor(tc.configured, tc.requireOrigin); got != tc.want {
t.Errorf("AppFloor(%q, %t) = %q, want %q", tc.configured, tc.requireOrigin, got, tc.want)
}
}
}