mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-21 02:17:36 +00:00
ipn: move ParseAutoExitNodeID from ipn/ipnlocal to ipn
So it can be used from the CLI without importing ipnlocal. While there, also remove isAutoExitNodeID, a wrapper around parseAutoExitNodeID that's no longer used. Updates tailscale/corp#29969 Updates #cleanup Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -1129,3 +1129,62 @@ func TestPrefsDowngrade(t *testing.T) {
|
||||
t.Fatal("AllowSingleHosts should be true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAutoExitNodeString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
exitNodeID string
|
||||
wantOk bool
|
||||
wantExpr ExitNodeExpression
|
||||
}{
|
||||
{
|
||||
name: "empty expr",
|
||||
exitNodeID: "",
|
||||
wantOk: false,
|
||||
wantExpr: "",
|
||||
},
|
||||
{
|
||||
name: "no auto prefix",
|
||||
exitNodeID: "foo",
|
||||
wantOk: false,
|
||||
wantExpr: "",
|
||||
},
|
||||
{
|
||||
name: "auto:any",
|
||||
exitNodeID: "auto:any",
|
||||
wantOk: true,
|
||||
wantExpr: AnyExitNode,
|
||||
},
|
||||
{
|
||||
name: "auto:foo",
|
||||
exitNodeID: "auto:foo",
|
||||
wantOk: true,
|
||||
wantExpr: "foo",
|
||||
},
|
||||
{
|
||||
name: "auto prefix but empty suffix",
|
||||
exitNodeID: "auto:",
|
||||
wantOk: false,
|
||||
wantExpr: "",
|
||||
},
|
||||
{
|
||||
name: "auto prefix no colon",
|
||||
exitNodeID: "auto",
|
||||
wantOk: false,
|
||||
wantExpr: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotExpr, gotOk := ParseAutoExitNodeString(tt.exitNodeID)
|
||||
if gotOk != tt.wantOk || gotExpr != tt.wantExpr {
|
||||
if tt.wantOk {
|
||||
t.Fatalf("got %v (%q); want %v (%q)", gotOk, gotExpr, tt.wantOk, tt.wantExpr)
|
||||
} else {
|
||||
t.Fatalf("got %v (%q); want false", gotOk, gotExpr)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user