platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
59
selective-vpn-api/app/vpn_locations_cache_test.go
Normal file
59
selective-vpn-api/app/vpn_locations_cache_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseVPNLocationsOutput(t *testing.T) {
|
||||
raw := `
|
||||
ISO Country Region Ping
|
||||
DE Germany Frankfurt 35
|
||||
US United States New-York 120
|
||||
US United States Los-Angeles 130
|
||||
`
|
||||
|
||||
locs, err := parseVPNLocationsOutput(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("parseVPNLocationsOutput returned error: %v", err)
|
||||
}
|
||||
if len(locs) != 3 {
|
||||
t.Fatalf("expected 3 locations, got %d", len(locs))
|
||||
}
|
||||
if locs[0].ISO != "DE" || locs[1].ISO != "US" || locs[2].ISO != "US" {
|
||||
t.Fatalf("unexpected iso order: %+v", locs)
|
||||
}
|
||||
if locs[1].Target != "New-York" {
|
||||
t.Fatalf("unexpected target parse: %+v", locs[1])
|
||||
}
|
||||
if locs[2].Target != "Los-Angeles" {
|
||||
t.Fatalf("unexpected target parse: %+v", locs[2])
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseVPNLocationsOutputRejectsInvalid(t *testing.T) {
|
||||
raw := "error: not logged in\ntry: adguardvpn-cli-root login\n"
|
||||
if _, err := parseVPNLocationsOutput(raw); err == nil {
|
||||
t.Fatal("expected parse error for invalid output, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInferVPNLocationTargetFromLabel(t *testing.T) {
|
||||
got := inferVPNLocationTargetFromLabel("US United States Los Angeles (271 ms)", "US")
|
||||
if got != "United States Los Angeles" {
|
||||
t.Fatalf("unexpected target for basic label: %q", got)
|
||||
}
|
||||
got = inferVPNLocationTargetFromLabel("RU Russia Moscow (Virtual) (29 ms)", "RU")
|
||||
if got != "Russia Moscow (Virtual)" {
|
||||
t.Fatalf("unexpected target for virtual label: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommonPrefixTokens(t *testing.T) {
|
||||
in := [][]string{
|
||||
{"United", "States", "Los", "Angeles"},
|
||||
{"United", "States", "Boston"},
|
||||
{"United", "States", "Seattle"},
|
||||
}
|
||||
pfx := commonPrefixTokens(in)
|
||||
if len(pfx) != 2 || pfx[0] != "United" || pfx[1] != "States" {
|
||||
t.Fatalf("unexpected common prefix: %#v", pfx)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user