ooni-probe-cli/internal/netxlite/mocks/http3_test.go
Simone Basso 493b72b170
refactor(netxlite): improve tests for http and http3 (#487)
* refactor(netxlite): improve tests for http and http3

See https://github.com/ooni/probe/issues/1591

* Update internal/netxlite/http3.go
2021-09-08 00:59:48 +02:00

38 lines
755 B
Go

package mocks
import (
"errors"
"net/http"
"testing"
)
func TestHTTP3RoundTripper(t *testing.T) {
t.Run("RoundTrip", func(t *testing.T) {
expected := errors.New("mocked error")
txp := &HTTP3RoundTripper{
MockRoundTrip: func(req *http.Request) (*http.Response, error) {
return nil, expected
},
}
resp, err := txp.RoundTrip(&http.Request{})
if !errors.Is(err, expected) {
t.Fatal("unexpected err", err)
}
if resp != nil {
t.Fatal("unexpected resp")
}
})
t.Run("Close", func(t *testing.T) {
expected := errors.New("mocked error")
txp := &HTTP3RoundTripper{
MockClose: func() error {
return expected
},
}
if err := txp.Close(); !errors.Is(err, expected) {
t.Fatal("unexpected err", err)
}
})
}