67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBuildTransportPolicyAdGuardTargetFromObservation(t *testing.T) {
|
|
now := time.Date(2026, time.March, 23, 19, 0, 0, 0, time.UTC)
|
|
item := buildTransportPolicyAdGuardTargetFromObservation(
|
|
"active",
|
|
"CONNECTED",
|
|
"after connect: CONNECTED; raw: Connected to HELSINKI in TUN mode, running on tun0",
|
|
now,
|
|
)
|
|
|
|
if item.ID != transportPolicyTargetAdGuardID {
|
|
t.Fatalf("unexpected id: %#v", item)
|
|
}
|
|
if item.Kind != TransportClientKind(transportPolicyTargetAdGuardID) {
|
|
t.Fatalf("unexpected kind: %#v", item)
|
|
}
|
|
if item.Status != TransportClientUp {
|
|
t.Fatalf("unexpected status: %#v", item)
|
|
}
|
|
if item.Iface != "tun0" {
|
|
t.Fatalf("unexpected iface: %#v", item)
|
|
}
|
|
if item.RoutingTable != transportPolicyTargetAdGuardTable {
|
|
t.Fatalf("unexpected routing table: %#v", item)
|
|
}
|
|
if len(item.Runtime.AllowedActions) != 3 || item.Runtime.AllowedActions[0] != "start" {
|
|
t.Fatalf("unexpected allowed actions: %#v", item.Runtime)
|
|
}
|
|
}
|
|
|
|
func TestTransportClientMatchesKindFilter(t *testing.T) {
|
|
it := TransportClient{Kind: TransportClientKind("adguardvpn")}
|
|
if !transportClientMatchesKindFilter(it, "adguardvpn", "") {
|
|
t.Fatalf("expected raw kind match for adguard virtual client")
|
|
}
|
|
if transportClientMatchesKindFilter(it, "singbox", TransportClientSingBox) {
|
|
t.Fatalf("unexpected known kind match")
|
|
}
|
|
}
|
|
|
|
func TestTransportVirtualAdGuardSystemdAction(t *testing.T) {
|
|
if got, ok := transportVirtualAdGuardSystemdAction("start"); !ok || got != "start" {
|
|
t.Fatalf("unexpected start mapping: %q %v", got, ok)
|
|
}
|
|
if got, ok := transportVirtualAdGuardSystemdAction("ReStArT"); !ok || got != "restart" {
|
|
t.Fatalf("unexpected restart mapping: %q %v", got, ok)
|
|
}
|
|
if _, ok := transportVirtualAdGuardSystemdAction("provision"); ok {
|
|
t.Fatalf("unexpected mapping for unsupported action")
|
|
}
|
|
}
|
|
|
|
func TestTransportRuntimeObservabilityScopeForClientID(t *testing.T) {
|
|
if got := transportRuntimeObservabilityScopeForClientID("adguardvpn"); got != "adguardvpn" {
|
|
t.Fatalf("unexpected adguard scope: %q", got)
|
|
}
|
|
if got := transportRuntimeObservabilityScopeForClientID("sb-one"); got != "transport:sb-one" {
|
|
t.Fatalf("unexpected transport scope: %q", got)
|
|
}
|
|
}
|