diff --git a/internal/netxlite/http_test.go b/internal/netxlite/http_test.go index 417799b..bf4966c 100644 --- a/internal/netxlite/http_test.go +++ b/internal/netxlite/http_test.go @@ -75,7 +75,12 @@ func TestHTTPTransportLogger(t *testing.T) { }, } client := &http.Client{Transport: txp} - resp, err := client.Get("https://www.google.com") + req, err := http.NewRequest("GET", "https://www.google.com", nil) + if err != nil { + t.Fatal(err) + } + req.Header.Set("User-Agent", "miniooni/0.1.0-dev") + resp, err := client.Do(req) if err != nil { t.Fatal(err) } diff --git a/internal/netxlite/quic.go b/internal/netxlite/quic.go index ebb3182..7193ecb 100644 --- a/internal/netxlite/quic.go +++ b/internal/netxlite/quic.go @@ -394,6 +394,16 @@ func (c *quicErrWrapperUDPLikeConn) ReadFrom(b []byte) (int, net.Addr, error) { return n, addr, nil } +// Close implements quicx.UDPLikeConn.Close. +func (c *quicErrWrapperUDPLikeConn) Close() error { + err := c.UDPLikeConn.Close() + if err != nil { + return errorsx.NewErrWrapper( + errorsx.ClassifyGenericError, errorsx.ReadFromOperation, err) + } + return nil +} + // quicDialerErrWrapper is a dialer that performs quic err wrapping type quicDialerErrWrapper struct { QUICDialer diff --git a/internal/netxlite/quic_test.go b/internal/netxlite/quic_test.go index 06eb7da..a7848b1 100644 --- a/internal/netxlite/quic_test.go +++ b/internal/netxlite/quic_test.go @@ -472,6 +472,7 @@ func TestQUICLoggerDialer(t *testing.T) { func TestNewSingleUseQUICDialer(t *testing.T) { sess := &mocks.QUICEarlySession{} qd := NewSingleUseQUICDialer(sess) + defer qd.CloseIdleConnections() outsess, err := qd.DialContext( context.Background(), "", "", &tls.Config{}, &quic.Config{}) if err != nil { @@ -618,6 +619,37 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) { } }) }) + + t.Run("Close", func(t *testing.T) { + t.Run("on success", func(t *testing.T) { + conn := &quicErrWrapperUDPLikeConn{ + UDPLikeConn: &mocks.QUICUDPLikeConn{ + MockClose: func() error { + return nil + }, + }, + } + err := conn.Close() + if err != nil { + t.Fatal(err) + } + }) + + t.Run("on failure", func(t *testing.T) { + expectedErr := io.EOF + conn := &quicErrWrapperUDPLikeConn{ + UDPLikeConn: &mocks.QUICUDPLikeConn{ + MockClose: func() error { + return expectedErr + }, + }, + } + err := conn.Close() + if err == nil || err.Error() != errorsx.FailureEOFError { + t.Fatal("unexpected err", err) + } + }) + }) } func TestQUICDialerErrWrapper(t *testing.T) {