refactor: move ErrorWrapperQUICDialer to errorsx (#420)
I needed to add some tests as integration tests due to circular imports, but this is ~fine because we quite likely want many integration tests in the errorsx package anyway. Part of https://github.com/ooni/probe/issues/1505.
This commit is contained in:
parent
5c52d99d57
commit
ec350cba1a
6 changed files with 132 additions and 116 deletions
39
internal/errorsx/quic_test.go
Normal file
39
internal/errorsx/quic_test.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package errorsx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxmocks"
|
||||
)
|
||||
|
||||
func TestErrorWrapperQUICDialerFailure(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
d := &ErrorWrapperQUICDialer{Dialer: &netxmocks.QUICContextDialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||
return nil, io.EOF
|
||||
},
|
||||
}}
|
||||
sess, err := d.DialContext(
|
||||
ctx, "udp", "www.google.com:443", &tls.Config{}, &quic.Config{})
|
||||
if sess != nil {
|
||||
t.Fatal("expected a nil sess here")
|
||||
}
|
||||
if !errors.Is(err, io.EOF) {
|
||||
t.Fatal("expected another error here")
|
||||
}
|
||||
var errWrapper *ErrWrapper
|
||||
if !errors.As(err, &errWrapper) {
|
||||
t.Fatal("cannot cast to ErrWrapper")
|
||||
}
|
||||
if errWrapper.Operation != QUICHandshakeOperation {
|
||||
t.Fatal("unexpected Operation")
|
||||
}
|
||||
if errWrapper.Failure != FailureEOFError {
|
||||
t.Fatal("unexpected failure")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue