feat(httpx): improve testing using the fakefiller (#649)

This diff extracts the fakefiller inside of internal/ooapi (a
currently unused package) into its own package.

The fakefiller knows how to fill many fields that are typically
shared as data structures across processes.

It is not perfect in that it cannot fill logger or http client
fields, but still helps with better filling and testing.

So, here we're using the fakefiller to improve testing of httpx
and, nicely enough, we've already catched a bug in the way in
which APIClientTemplate.Build misses to forward Authorization from
the original template. Yay!

Work part of https://github.com/ooni/probe/issues/1951
This commit is contained in:
Simone Basso 2022-01-05 14:49:31 +01:00 committed by GitHub
commit 93f084598e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 433 additions and 337 deletions

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:56.092704 +0200 CEST m=+0.000214376
// 2022-01-04 17:58:21.011087899 +0100 CET m=+0.000148552
package ooapi
@ -28,7 +28,7 @@ func TestCheckReportIDInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -47,7 +47,7 @@ func TestCheckReportIDWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -65,7 +65,7 @@ func TestCheckReportIDWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -83,7 +83,7 @@ func TestCheckReportIDWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -101,7 +101,7 @@ func TestCheckReportIDWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -123,7 +123,7 @@ func TestCheckReportIDWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -146,7 +146,7 @@ func TestCheckReportIDWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -191,7 +191,7 @@ func (h *handleCheckReportID) ServeHTTP(w http.ResponseWriter, r *http.Request)
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.CheckReportIDResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -208,9 +208,9 @@ func TestCheckReportIDRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleCheckReportIDAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -273,7 +273,7 @@ func TestCheckInInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -292,7 +292,7 @@ func TestCheckInWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -310,7 +310,7 @@ func TestCheckInMarshalErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -328,7 +328,7 @@ func TestCheckInWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -346,7 +346,7 @@ func TestCheckInWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -364,7 +364,7 @@ func TestCheckInWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -386,7 +386,7 @@ func TestCheckInWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -409,7 +409,7 @@ func TestCheckInWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -454,7 +454,7 @@ func (h *handleCheckIn) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.CheckInResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -471,9 +471,9 @@ func TestCheckInRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleCheckInAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -518,7 +518,7 @@ func TestLoginInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -537,7 +537,7 @@ func TestLoginWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -555,7 +555,7 @@ func TestLoginMarshalErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -573,7 +573,7 @@ func TestLoginWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -591,7 +591,7 @@ func TestLoginWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -609,7 +609,7 @@ func TestLoginWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -631,7 +631,7 @@ func TestLoginWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -654,7 +654,7 @@ func TestLoginWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -699,7 +699,7 @@ func (h *handleLogin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.LoginResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -716,9 +716,9 @@ func TestLoginRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleLoginAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -763,7 +763,7 @@ func TestMeasurementMetaInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -782,7 +782,7 @@ func TestMeasurementMetaWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -800,7 +800,7 @@ func TestMeasurementMetaWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -818,7 +818,7 @@ func TestMeasurementMetaWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -836,7 +836,7 @@ func TestMeasurementMetaWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -858,7 +858,7 @@ func TestMeasurementMetaWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -881,7 +881,7 @@ func TestMeasurementMetaWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -926,7 +926,7 @@ func (h *handleMeasurementMeta) ServeHTTP(w http.ResponseWriter, r *http.Request
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.MeasurementMetaResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -943,9 +943,9 @@ func TestMeasurementMetaRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleMeasurementMetaAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -1008,7 +1008,7 @@ func TestRegisterInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -1027,7 +1027,7 @@ func TestRegisterWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1045,7 +1045,7 @@ func TestRegisterMarshalErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1063,7 +1063,7 @@ func TestRegisterWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1081,7 +1081,7 @@ func TestRegisterWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -1099,7 +1099,7 @@ func TestRegisterWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -1121,7 +1121,7 @@ func TestRegisterWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1144,7 +1144,7 @@ func TestRegisterWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1189,7 +1189,7 @@ func (h *handleRegister) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.RegisterResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -1206,9 +1206,9 @@ func TestRegisterRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleRegisterAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -1253,7 +1253,7 @@ func TestTestHelpersInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -1272,7 +1272,7 @@ func TestTestHelpersWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1290,7 +1290,7 @@ func TestTestHelpersWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1308,7 +1308,7 @@ func TestTestHelpersWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -1326,7 +1326,7 @@ func TestTestHelpersWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -1348,7 +1348,7 @@ func TestTestHelpersWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1371,7 +1371,7 @@ func TestTestHelpersWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1416,7 +1416,7 @@ func (h *handleTestHelpers) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.userAgent = r.Header.Get("User-Agent")
var out apimodel.TestHelpersResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -1433,9 +1433,9 @@ func TestTestHelpersRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleTestHelpersAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -1484,7 +1484,7 @@ func TestTestHelpersResponseLiteralNull(t *testing.T) {
ctx := context.Background()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrJSONLiteralNull) {
t.Fatal("not the error we expected", err)
@ -1501,7 +1501,7 @@ func TestPsiphonConfigInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -1516,7 +1516,7 @@ func TestPsiphonConfigWithMissingToken(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrMissingToken) {
t.Fatal("not the error we expected", err)
@ -1536,7 +1536,7 @@ func TestPsiphonConfigWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1555,7 +1555,7 @@ func TestPsiphonConfigWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1574,7 +1574,7 @@ func TestPsiphonConfigWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -1593,7 +1593,7 @@ func TestPsiphonConfigWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -1616,7 +1616,7 @@ func TestPsiphonConfigWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1640,7 +1640,7 @@ func TestPsiphonConfigWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1685,7 +1685,7 @@ func (h *handlePsiphonConfig) ServeHTTP(w http.ResponseWriter, r *http.Request)
h.userAgent = r.Header.Get("User-Agent")
var out apimodel.PsiphonConfigResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -1702,10 +1702,10 @@ func TestPsiphonConfigRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simplePsiphonConfigAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.fill(&api.Token)
ff.Fill(&api.UserAgent)
ff.Fill(&api.Token)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -1755,7 +1755,7 @@ func TestPsiphonConfigResponseLiteralNull(t *testing.T) {
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrJSONLiteralNull) {
t.Fatal("not the error we expected", err)
@ -1772,7 +1772,7 @@ func TestTorTargetsInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -1787,7 +1787,7 @@ func TestTorTargetsWithMissingToken(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrMissingToken) {
t.Fatal("not the error we expected", err)
@ -1807,7 +1807,7 @@ func TestTorTargetsWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1826,7 +1826,7 @@ func TestTorTargetsWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1845,7 +1845,7 @@ func TestTorTargetsWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -1864,7 +1864,7 @@ func TestTorTargetsWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -1887,7 +1887,7 @@ func TestTorTargetsWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1911,7 +1911,7 @@ func TestTorTargetsWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -1956,7 +1956,7 @@ func (h *handleTorTargets) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.userAgent = r.Header.Get("User-Agent")
var out apimodel.TorTargetsResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -1973,10 +1973,10 @@ func TestTorTargetsRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleTorTargetsAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.fill(&api.Token)
ff.Fill(&api.UserAgent)
ff.Fill(&api.Token)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -2026,7 +2026,7 @@ func TestTorTargetsResponseLiteralNull(t *testing.T) {
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrJSONLiteralNull) {
t.Fatal("not the error we expected", err)
@ -2043,7 +2043,7 @@ func TestURLsInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -2062,7 +2062,7 @@ func TestURLsWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2080,7 +2080,7 @@ func TestURLsWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2098,7 +2098,7 @@ func TestURLsWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -2116,7 +2116,7 @@ func TestURLsWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -2138,7 +2138,7 @@ func TestURLsWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2161,7 +2161,7 @@ func TestURLsWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2206,7 +2206,7 @@ func (h *handleURLs) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.URLsResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -2223,9 +2223,9 @@ func TestURLsRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleURLsAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -2270,7 +2270,7 @@ func TestOpenReportInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -2289,7 +2289,7 @@ func TestOpenReportWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2307,7 +2307,7 @@ func TestOpenReportMarshalErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2325,7 +2325,7 @@ func TestOpenReportWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2343,7 +2343,7 @@ func TestOpenReportWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -2361,7 +2361,7 @@ func TestOpenReportWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -2383,7 +2383,7 @@ func TestOpenReportWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2406,7 +2406,7 @@ func TestOpenReportWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2451,7 +2451,7 @@ func (h *handleOpenReport) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.OpenReportResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -2468,9 +2468,9 @@ func TestOpenReportRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleOpenReportAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -2515,7 +2515,7 @@ func TestSubmitMeasurementInvalidURL(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
t.Fatal("not the error we expected", err)
@ -2534,7 +2534,7 @@ func TestSubmitMeasurementWithHTTPErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2552,7 +2552,7 @@ func TestSubmitMeasurementMarshalErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2570,7 +2570,7 @@ func TestSubmitMeasurementWithNewRequestErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2588,7 +2588,7 @@ func TestSubmitMeasurementWith401(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrUnauthorized) {
t.Fatal("not the error we expected", err)
@ -2606,7 +2606,7 @@ func TestSubmitMeasurementWith400(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, ErrHTTPFailure) {
t.Fatal("not the error we expected", err)
@ -2628,7 +2628,7 @@ func TestSubmitMeasurementWithResponseBodyReadErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2651,7 +2651,7 @@ func TestSubmitMeasurementWithUnmarshalFailure(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)
@ -2696,7 +2696,7 @@ func (h *handleSubmitMeasurement) ServeHTTP(w http.ResponseWriter, r *http.Reque
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.SubmitMeasurementResponse
ff := fakeFill{}
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@ -2713,9 +2713,9 @@ func TestSubmitMeasurementRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
api := &simpleSubmitMeasurementAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.Fill(&api.UserAgent)
// issue request
ctx := context.Background()
resp, err := api.Call(ctx, req)
@ -2765,7 +2765,7 @@ func TestSubmitMeasurementTemplateErr(t *testing.T) {
ctx := context.Background()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(req)
ff.Fill(req)
resp, err := api.Call(ctx, req)
if !errors.Is(err, errMocked) {
t.Fatal("not the error we expected", err)