netxlite: code quality, improve tests, docs (#494)

See https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso 2021-09-08 22:48:10 +02:00 committed by GitHub
commit 50b58672c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 318 additions and 154 deletions

View file

@ -21,8 +21,17 @@ import (
func TestHTTPTransportLogger(t *testing.T) {
t.Run("RoundTrip", func(t *testing.T) {
t.Run("with failure", func(t *testing.T) {
var count int
lo := &mocks.Logger{
MockDebug: func(message string) {
count++
},
MockDebugf: func(format string, v ...interface{}) {
count++
},
}
txp := &httpTransportLogger{
Logger: log.Log,
Logger: lo,
HTTPTransport: &mocks.HTTPTransport{
MockRoundTrip: func(req *http.Request) (*http.Response, error) {
return nil, io.EOF
@ -37,6 +46,9 @@ func TestHTTPTransportLogger(t *testing.T) {
if resp != nil {
t.Fatal("expected nil response here")
}
if count < 1 {
t.Fatal("no logs?!")
}
})
t.Run("we add the host header", func(t *testing.T) {
@ -73,8 +85,17 @@ func TestHTTPTransportLogger(t *testing.T) {
})
t.Run("with success", func(t *testing.T) {
var count int
lo := &mocks.Logger{
MockDebug: func(message string) {
count++
},
MockDebugf: func(format string, v ...interface{}) {
count++
},
}
txp := &httpTransportLogger{
Logger: log.Log,
Logger: lo,
HTTPTransport: &mocks.HTTPTransport{
MockRoundTrip: func(req *http.Request) (*http.Response, error) {
return &http.Response{
@ -94,6 +115,9 @@ func TestHTTPTransportLogger(t *testing.T) {
}
iox.ReadAllContext(context.Background(), resp.Body)
resp.Body.Close()
if count < 1 {
t.Fatal("no logs?!")
}
})
})