Files
Pulse/pkg/tlsutil/dnscache_test.go
rcourtman 3fdf753a5b Enhance devcontainer and CI workflows
- Add persistent volume mounts for Go/npm caches (faster rebuilds)
- Add shell config with helpful aliases and custom prompt
- Add comprehensive devcontainer documentation
- Add pre-commit hooks for Go formatting and linting
- Use go-version-file in CI workflows instead of hardcoded versions
- Simplify docker compose commands with --wait flag
- Add gitignore entries for devcontainer auth files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 22:29:15 +00:00

61 lines
1.2 KiB
Go

package tlsutil
import (
"context"
"net"
"testing"
"time"
)
func TestDialContextWithCache_Success(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("listen: %v", err)
}
defer ln.Close()
done := make(chan struct{})
go func() {
defer close(done)
conn, err := ln.Accept()
if err == nil {
_ = conn.Close()
}
}()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
conn, err := DialContextWithCache(ctx, "tcp", ln.Addr().String())
if err != nil {
t.Fatalf("DialContextWithCache: %v", err)
}
_ = conn.Close()
select {
case <-done:
case <-time.After(2 * time.Second):
t.Fatalf("server did not accept connection")
}
}
func TestDialContextWithCache_BadAddress(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err := DialContextWithCache(ctx, "tcp", "missing-port")
if err == nil {
t.Fatalf("expected error")
}
}
func TestDialContextWithCache_UnresolvableHost(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err := DialContextWithCache(ctx, "tcp", "this-domain-should-not-exist.invalid:80")
if err == nil {
t.Fatalf("expected error")
}
}