fix(netxlite/quic): wrap Close (#509)

While there, make sure netxlite has 100% coverage.

Part of https://github.com/ooni/probe/issues/1733 and diff
has been extracted from https://github.com/ooni/probe-cli/pull/506.
This commit is contained in:
Simone Basso 2021-09-27 14:14:17 +02:00 committed by GitHub
commit 273774bb03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 1 deletions

View file

@ -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) {