refactor(engine): *http.Client -> model.HTTPClient (#836)
This diff makes the implementation of the engine package more abstract by changing HTTPClient() to return a model.HTTPClient as opposed to returning an *http.Client. Part of https://github.com/ooni/probe/issues/2184
This commit is contained in:
parent
d419ed8ac8
commit
6019b25baf
|
@ -3,7 +3,6 @@ package mockable
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/probeservices"
|
||||
|
@ -14,7 +13,7 @@ import (
|
|||
// Session allows to mock sessions.
|
||||
type Session struct {
|
||||
MockableTestHelpers map[string][]model.OOAPIService
|
||||
MockableHTTPClient *http.Client
|
||||
MockableHTTPClient model.HTTPClient
|
||||
MockableLogger model.Logger
|
||||
MockableMaybeResolverIP string
|
||||
MockableProbeASNString string
|
||||
|
@ -45,7 +44,7 @@ func (sess *Session) GetTestHelpersByName(name string) ([]model.OOAPIService, bo
|
|||
}
|
||||
|
||||
// DefaultHTTPClient implements ExperimentSession.DefaultHTTPClient
|
||||
func (sess *Session) DefaultHTTPClient() *http.Client {
|
||||
func (sess *Session) DefaultHTTPClient() model.HTTPClient {
|
||||
return sess.MockableHTTPClient
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ package probeservices
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||
|
@ -56,7 +55,7 @@ var (
|
|||
|
||||
// Session is how this package sees a Session.
|
||||
type Session interface {
|
||||
DefaultHTTPClient() *http.Client
|
||||
DefaultHTTPClient() model.HTTPClient
|
||||
KeyValueStore() model.KeyValueStore
|
||||
Logger() model.Logger
|
||||
ProxyURL() *url.URL
|
||||
|
|
|
@ -337,7 +337,7 @@ func (s *Session) GetTestHelpersByName(name string) ([]model.OOAPIService, bool)
|
|||
}
|
||||
|
||||
// DefaultHTTPClient returns the session's default HTTP client.
|
||||
func (s *Session) DefaultHTTPClient() *http.Client {
|
||||
func (s *Session) DefaultHTTPClient() model.HTTPClient {
|
||||
return &http.Client{Transport: s.httpDefaultTransport}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,11 @@ func TestSessionByteCounter(t *testing.T) {
|
|||
}
|
||||
s := newSessionForTesting(t)
|
||||
client := s.DefaultHTTPClient()
|
||||
resp, err := client.Get("https://www.google.com")
|
||||
req, err := http.NewRequest("GET", "https://www.google.com", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package model
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//
|
||||
|
@ -13,7 +12,7 @@ import (
|
|||
// ExperimentSession is the experiment's view of a session.
|
||||
type ExperimentSession interface {
|
||||
GetTestHelpersByName(name string) ([]OOAPIService, bool)
|
||||
DefaultHTTPClient() *http.Client
|
||||
DefaultHTTPClient() HTTPClient
|
||||
FetchPsiphonConfig(ctx context.Context) ([]byte, error)
|
||||
FetchTorTargets(ctx context.Context, cc string) (map[string]OOAPITorTarget, error)
|
||||
FetchURLList(ctx context.Context, config OOAPIURLListConfig) ([]OOAPIURLInfo, error)
|
||||
|
|
Loading…
Reference in New Issue
Block a user