refactor(handler/tunnel): code review fixes and entrypoint subpackage extraction
- Fix dead-code branch in bind.go host assignment (always use endpoint hash) - Return descriptive error on bypass match in connect.go (was masking as success) - Update bypass test in connect_test.go for new error behavior - Extract entrypoint subpackage from monolithic entrypoint.go (6 files) - Fix observeStats event-loss bug (break -> fallthrough on retry success) - Add 47 unit tests across handler, connect, bind, metadata packages - Add architecture doc comments to all key files - Build and vet clean, 173 tests pass with -race
This commit is contained in:
+12
-12
@@ -9,14 +9,14 @@ import (
|
||||
|
||||
func TestParseTunnelID(t *testing.T) {
|
||||
t.Run("empty string", func(t *testing.T) {
|
||||
tid := parseTunnelID("")
|
||||
tid := ParseTunnelID("")
|
||||
if !tid.IsZero() {
|
||||
t.Error("expected zero tunnel ID for empty string")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("valid uuid", func(t *testing.T) {
|
||||
tid := parseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
tid := ParseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
if tid.IsZero() {
|
||||
t.Error("expected non-zero tunnel ID")
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func TestParseTunnelID(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("valid uuid with $ prefix", func(t *testing.T) {
|
||||
tid := parseTunnelID("$6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
tid := ParseTunnelID("$6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
if tid.IsZero() {
|
||||
t.Error("expected non-zero tunnel ID")
|
||||
}
|
||||
@@ -36,14 +36,14 @@ func TestParseTunnelID(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("invalid uuid", func(t *testing.T) {
|
||||
tid := parseTunnelID("not-a-uuid")
|
||||
tid := ParseTunnelID("not-a-uuid")
|
||||
if !tid.IsZero() {
|
||||
t.Error("expected zero tunnel ID for invalid input")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("invalid uuid with $ prefix", func(t *testing.T) {
|
||||
tid := parseTunnelID("$not-a-uuid")
|
||||
tid := ParseTunnelID("$not-a-uuid")
|
||||
if !tid.IsZero() {
|
||||
t.Error("expected zero tunnel ID for invalid input")
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func TestParseTunnelID(t *testing.T) {
|
||||
|
||||
func TestParseTunnelID_PrivateMarker(t *testing.T) {
|
||||
t.Run("dollar not at start", func(t *testing.T) {
|
||||
tid := parseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
tid := ParseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
if tid.IsPrivate() {
|
||||
t.Error("expected non-private when $ is not at start")
|
||||
}
|
||||
@@ -60,17 +60,17 @@ func TestParseTunnelID_PrivateMarker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseTunnelID_RoundTrip(t *testing.T) {
|
||||
original := parseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
original := ParseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
t.Logf("original string: %s", original.String())
|
||||
|
||||
reparsed := parseTunnelID(original.String())
|
||||
reparsed := ParseTunnelID(original.String())
|
||||
if !original.Equal(reparsed) {
|
||||
t.Errorf("round-trip failed: original=%v reparsed=%v", original, reparsed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTunnelID_PrivateRoundTrip(t *testing.T) {
|
||||
original := parseTunnelID("$6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
original := ParseTunnelID("$6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
if !original.IsPrivate() {
|
||||
t.Fatal("expected private tunnel ID")
|
||||
}
|
||||
@@ -79,19 +79,19 @@ func TestParseTunnelID_PrivateRoundTrip(t *testing.T) {
|
||||
// The private flag is carried in the struct, not in the string representation.
|
||||
// Reparsing from String() gives a non-private ID because the $ prefix is not
|
||||
// part of the relay.TunnelID.String() output.
|
||||
reparsed := parseTunnelID(original.String())
|
||||
reparsed := ParseTunnelID(original.String())
|
||||
if !original.Equal(reparsed) {
|
||||
t.Errorf("round-trip failed: original=%v reparsed=%v", original, reparsed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTunnelID_RelayCompatibility(t *testing.T) {
|
||||
id := parseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
id := ParseTunnelID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
u, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
var raw [16]byte
|
||||
copy(raw[:], u[:])
|
||||
expected := relay.NewTunnelID(raw[:])
|
||||
if !id.Equal(expected) {
|
||||
t.Error("parseTunnelID result should match relay.NewTunnelID")
|
||||
t.Error("ParseTunnelID result should match relay.NewTunnelID")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user