mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-11-16 09:34:22 +08:00
48955fe57d
Adapt the port allocation option from #583 by xigua761 without its commercial licensing changes. Serialize forward, chain, peer runtime, cleanup and import reservations across SQLite/PostgreSQL instances. Co-authored-by: xigua761 <xigua1166@outlook.com>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package handler
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeSequentialPortConfigValue(t *testing.T) {
|
|
for in, want := range map[string]string{"true": "true", " FALSE ": "false"} {
|
|
got, err := normalizeAndValidateConfigValue(sequentialPortConfigKey, in)
|
|
if err != nil || got != want {
|
|
t.Fatalf("value %q: got %q err=%v, want %q", in, got, err, want)
|
|
}
|
|
}
|
|
if _, err := normalizeAndValidateConfigValue(sequentialPortConfigKey, "maybe"); err == nil {
|
|
t.Fatal("expected invalid value to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestSequentialPortConfigReadsRepositoryAndDefaultsOff(t *testing.T) {
|
|
_, r := setupConfigAccessTestRouter(t)
|
|
h := &Handler{repo: r}
|
|
if h.isSequentialPortEnabled() {
|
|
t.Fatal("missing config must preserve random allocation")
|
|
}
|
|
for _, tc := range []struct {
|
|
value string
|
|
want bool
|
|
}{
|
|
{"true", true}, {" TRUE ", true}, {"false", false}, {"invalid", false},
|
|
} {
|
|
seedConfigValue(t, r, sequentialPortConfigKey, tc.value)
|
|
if got := h.isSequentialPortEnabled(); got != tc.want {
|
|
t.Fatalf("config %q: got %v, want %v", tc.value, got, tc.want)
|
|
}
|
|
}
|
|
}
|