platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
67
selective-vpn-api/app/transportcfg/runtime_helpers_test.go
Normal file
67
selective-vpn-api/app/transportcfg/runtime_helpers_test.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package transportcfg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBackendUnitSingBoxUsesInstanceTemplateByDefault(t *testing.T) {
|
||||
client := Client{
|
||||
ID: "sg-realnetns",
|
||||
Kind: KindSingBox,
|
||||
}
|
||||
got := BackendUnit(client)
|
||||
if got != "singbox@sg-realnetns.service" {
|
||||
t.Fatalf("unexpected singbox unit: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackendUnitSingBoxTemplateConfigExpandsInstance(t *testing.T) {
|
||||
client := Client{
|
||||
ID: "sg-1",
|
||||
Kind: KindSingBox,
|
||||
Config: map[string]any{
|
||||
"unit": "singbox@.service",
|
||||
},
|
||||
}
|
||||
got := BackendUnit(client)
|
||||
if got != "singbox@sg-1.service" {
|
||||
t.Fatalf("unexpected template unit: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackendUnitSingBoxKeepsExplicitNonTemplateUnit(t *testing.T) {
|
||||
client := Client{
|
||||
ID: "sg-realnetns",
|
||||
Kind: KindSingBox,
|
||||
Config: map[string]any{
|
||||
"unit": "custom-singbox.service",
|
||||
},
|
||||
}
|
||||
got := BackendUnit(client)
|
||||
if got != "custom-singbox.service" {
|
||||
t.Fatalf("unexpected custom unit: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackendUnitNonSingBoxUnchanged(t *testing.T) {
|
||||
client := Client{
|
||||
ID: "dn-1",
|
||||
Kind: KindDNSTT,
|
||||
Config: map[string]any{
|
||||
"unit": "dnstt-custom.service",
|
||||
},
|
||||
}
|
||||
got := BackendUnit(client)
|
||||
if got != "dnstt-custom.service" {
|
||||
t.Fatalf("unexpected non-singbox unit: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackendUnitSingBoxSanitizesInstanceID(t *testing.T) {
|
||||
client := Client{
|
||||
ID: " SG Real/NetNS ",
|
||||
Kind: KindSingBox,
|
||||
}
|
||||
got := BackendUnit(client)
|
||||
if got != "singbox@sg-real-netns.service" {
|
||||
t.Fatalf("unexpected sanitized singbox unit: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user