68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
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)
|
|
}
|
|
}
|