From d19d4d6b3e1d246221aa1422ed6a1d3ee716f74e Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 4 Feb 2026 09:21:45 -0700 Subject: [PATCH] test withconn --- src/config_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/config_test.go b/src/config_test.go index 0643b60..9cfa449 100644 --- a/src/config_test.go +++ b/src/config_test.go @@ -1,7 +1,13 @@ package src import ( + "fmt" + "io" + "log" + "net" "os" + "strconv" + "sync" "testing" ) @@ -30,3 +36,37 @@ func TestConfigLoadEnv(t *testing.T) { t.Error("hello", c.Hello) } } + +func TestConfigWithConn(t *testing.T) { + log.SetOutput(io.Discard) + + c := Config{} + + seen0, seen1 := false, false + conn0, conn1 := &net.IPConn{}, &net.IPConn{} + pool0, pool1 := &sync.Pool{}, &sync.Pool{} + pool0.Put(conn0) + pool1.Put(conn1) + c.forwards = []*sync.Pool{pool0, pool1} + + for i := 0; i < 10; i++ { + i := strconv.Itoa(i) + t.Run(i, func(t *testing.T) { + if err := c.WithConn(i, func(c net.Conn) error { + c, _ = c.(*net.IPConn) + seen0 = seen0 || c == conn0 + seen1 = seen1 || c == conn1 + if c != conn0 && c != conn1 { + return fmt.Errorf("got unexepcted conn %v", c) + } + return nil + }); err != nil { + t.Fatal(err) + } + }) + } + + if !seen0 || !seen1 { + t.Fatalf("didnt see both conns") + } +}