fix(reduceErrors): return error when given an empty list (#675)

See https://github.com/ooni/probe/issues/1985 for context.

While there, ensure nextlite has 100% of coverage.
This commit is contained in:
Simone Basso 2022-01-26 12:18:36 +01:00 committed by GitHub
parent 4d50dd6d54
commit ce8ec5b391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 3 deletions

View File

@ -208,6 +208,7 @@ func TestDNSOverTCP(t *testing.T) {
if txp.Address() != address { if txp.Address() != address {
t.Fatal("invalid Address") t.Fatal("invalid Address")
} }
txp.CloseIdleConnections()
}) })
t.Run("other functions okay with TLS", func(t *testing.T) { t.Run("other functions okay with TLS", func(t *testing.T) {
@ -222,5 +223,6 @@ func TestDNSOverTCP(t *testing.T) {
if txp.Address() != address { if txp.Address() != address {
t.Fatal("invalid Address") t.Fatal("invalid Address")
} }
txp.CloseIdleConnections()
}) })
} }

View File

@ -59,6 +59,13 @@ func TestHTTP3Transport(t *testing.T) {
} }
}) })
t.Run("Network", func(t *testing.T) {
txp := &http3Transport{}
if txp.Network() != "quic" {
t.Fatal("unexpected .Network return value")
}
})
t.Run("RoundTrip", func(t *testing.T) { t.Run("RoundTrip", func(t *testing.T) {
expected := errors.New("mocked error") expected := errors.New("mocked error")
txp := &http3Transport{ txp := &http3Transport{

View File

@ -439,7 +439,6 @@ func TestHTTPTLSDialerWithReadTimeout(t *testing.T) {
} }
func TestNewHTTPTransportStdlib(t *testing.T) { func TestNewHTTPTransportStdlib(t *testing.T) {
// What to test about this factory?
txp := NewHTTPTransportStdlib(log.Log) txp := NewHTTPTransportStdlib(log.Log)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
cancel() // immediately! cancel() // immediately!
@ -454,6 +453,9 @@ func TestNewHTTPTransportStdlib(t *testing.T) {
if resp != nil { if resp != nil {
t.Fatal("unexpected resp") t.Fatal("unexpected resp")
} }
if txp.Network() != "tcp" {
t.Fatal("unexpected .Network return value")
}
txp.CloseIdleConnections() txp.CloseIdleConnections()
} }

View File

@ -9,6 +9,9 @@ import (
// the original netx implementation and that we cannot remove // the original netx implementation and that we cannot remove
// or change without thinking about the consequences. // or change without thinking about the consequences.
// See https://github.com/ooni/probe/issues/1985
var errReduceErrorsEmptyList = errors.New("bug: reduceErrors given an empty list")
// quirkReduceErrors finds a known error in a list of errors since // quirkReduceErrors finds a known error in a list of errors since
// it's probably most relevant. If this error is not found, just // it's probably most relevant. If this error is not found, just
// return the first error according to this reasoning: // return the first error according to this reasoning:
@ -31,7 +34,8 @@ import (
// See TODO(https://github.com/ooni/probe/issues/1779). // See TODO(https://github.com/ooni/probe/issues/1779).
func quirkReduceErrors(errorslist []error) error { func quirkReduceErrors(errorslist []error) error {
if len(errorslist) == 0 { if len(errorslist) == 0 {
return nil // See https://github.com/ooni/probe/issues/1985
return errReduceErrorsEmptyList
} }
for _, err := range errorslist { for _, err := range errorslist {
var wrapper *ErrWrapper var wrapper *ErrWrapper

View File

@ -10,7 +10,7 @@ import (
func TestQuirkReduceErrors(t *testing.T) { func TestQuirkReduceErrors(t *testing.T) {
t.Run("no errors", func(t *testing.T) { t.Run("no errors", func(t *testing.T) {
result := quirkReduceErrors(nil) result := quirkReduceErrors(nil)
if result != nil { if !errors.Is(result, errReduceErrorsEmptyList) {
t.Fatal("wrong result") t.Fatal("wrong result")
} }
}) })