WIP test but i think im done

This commit is contained in:
Bel LaPointe
2026-02-04 18:54:18 -07:00
parent 262e432344
commit 7dab9d2a0a
2 changed files with 57 additions and 2 deletions

View File

@@ -149,9 +149,10 @@ func (c Config) WithConn(hashKey string, foo func(net.Conn) error) error {
log.Printf("errored with conn %v: %v", hashIdx, err)
forwardConn.Close()
return err
} else {
log.Printf("release conn %v", hashIdx)
forward.Put(forwardConn)
}
log.Printf("release conn %v", hashIdx)
forward.Put(forwardConn)
return nil
}

54
src/listen_test.go Normal file
View File

@@ -0,0 +1,54 @@
package src
import (
"context"
"encoding/base64"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"time"
)
func TestListenLifecycle(t *testing.T) {
ctx, can := context.WithTimeout(context.Background(), time.Second*5)
defer can()
valkeyPort := getPort(t)
valkeyReady := make(chan struct{})
valkeyReadyCloserOnce := &sync.Once{}
go func() {
defer close(valkeyReady)
t.Fatal("not impl: start pretend valkey server")
}()
select {
case <-ctx.Done():
case <-valkeyReady:
}
config := Config{
ctx: ctx,
Listen: ":" + getPort(t),
Forwards: "127.0.0.1:" + valkeyPort,
Hello: base64.StdEncoding.EncodeToString([]byte("+ping\r\n")),
}
if err := config.setForwards(); err != nil {
t.Fatal(err)
}
go func() {
defer can()
t.Fatal("not impl: dial listen")
}()
if err := listen(ctx, config); err != nil {
t.Fatal(err)
}
}
func getPort(t *testing.T) string {
s := httptest.NewServer(http.HandlerFunc(http.NotFound))
s.Close()
return strings.Split(s.URL, ":")[2]
}