feat(ooapi): add toplevel client and simplify API (#248)

* feat(ooapi): add toplevel client and simplify API

This diff should simplify using ooapi from other packages by
adding more abstraction that wraps the existing code.

Part of https://github.com/ooni/probe/issues/1355.

* fix(ooapi): use correct comment for cloners

See https://github.com/ooni/probe-cli/pull/248#discussion_r590663843

* fix(ooapi): make sure the documentation is current

See https://github.com/ooni/probe-cli/pull/248#discussion_r590665773

* fix(ooapi): automate copying APIs

See https://github.com/ooni/probe-cli/pull/248#discussion_r590665837

* feat(ooapi): add unit tests for clientcall.go

See https://github.com/ooni/probe-cli/pull/248#discussion_r590666297

* fix(ooapi): rewrite integration tests to use toplevel API

See https://github.com/ooni/probe-cli/pull/248#discussion_r590665084
This commit is contained in:
Simone Basso 2021-03-19 09:30:42 +01:00 committed by GitHub
commit 28ce79eff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 2090 additions and 795 deletions

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-02-26 15:45:50.81792142 +0100 CET m=+0.000095792
// 2021-03-10 13:17:32.206416809 +0100 CET m=+0.000074280
package ooapi
@ -22,7 +22,7 @@ import (
)
func TestCheckReportIDInvalidURL(t *testing.T) {
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -41,7 +41,7 @@ func TestCheckReportIDInvalidURL(t *testing.T) {
func TestCheckReportIDWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -59,7 +59,7 @@ func TestCheckReportIDWithHTTPErr(t *testing.T) {
func TestCheckReportIDWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -77,7 +77,7 @@ func TestCheckReportIDWithNewRequestErr(t *testing.T) {
func TestCheckReportIDWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -95,7 +95,7 @@ func TestCheckReportIDWith401(t *testing.T) {
func TestCheckReportIDWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -117,7 +117,7 @@ func TestCheckReportIDWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -139,7 +139,7 @@ func TestCheckReportIDWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -209,7 +209,7 @@ func TestCheckReportIDRoundTrip(t *testing.T) {
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &CheckReportIDAPI{BaseURL: srvr.URL}
api := &simpleCheckReportIDAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -252,7 +252,7 @@ func TestCheckReportIDMandatoryFields(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{
StatusCode: 500,
}}
api := &CheckReportIDAPI{
api := &simpleCheckReportIDAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -267,7 +267,7 @@ func TestCheckReportIDMandatoryFields(t *testing.T) {
}
func TestCheckInInvalidURL(t *testing.T) {
api := &CheckInAPI{
api := &simpleCheckInAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -286,7 +286,7 @@ func TestCheckInInvalidURL(t *testing.T) {
func TestCheckInWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &CheckInAPI{
api := &simpleCheckInAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -304,7 +304,7 @@ func TestCheckInWithHTTPErr(t *testing.T) {
func TestCheckInMarshalErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &CheckInAPI{
api := &simpleCheckInAPI{
JSONCodec: &FakeCodec{EncodeErr: errMocked},
}
ctx := context.Background()
@ -322,7 +322,7 @@ func TestCheckInMarshalErr(t *testing.T) {
func TestCheckInWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &CheckInAPI{
api := &simpleCheckInAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -340,7 +340,7 @@ func TestCheckInWithNewRequestErr(t *testing.T) {
func TestCheckInWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &CheckInAPI{
api := &simpleCheckInAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -358,7 +358,7 @@ func TestCheckInWith401(t *testing.T) {
func TestCheckInWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &CheckInAPI{
api := &simpleCheckInAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -380,7 +380,7 @@ func TestCheckInWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &CheckInAPI{
api := &simpleCheckInAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -402,7 +402,7 @@ func TestCheckInWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &CheckInAPI{
api := &simpleCheckInAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -472,7 +472,7 @@ func TestCheckInRoundTrip(t *testing.T) {
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &CheckInAPI{BaseURL: srvr.URL}
api := &simpleCheckInAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -512,7 +512,7 @@ func TestCheckInRoundTrip(t *testing.T) {
}
func TestLoginInvalidURL(t *testing.T) {
api := &LoginAPI{
api := &simpleLoginAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -531,7 +531,7 @@ func TestLoginInvalidURL(t *testing.T) {
func TestLoginWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &LoginAPI{
api := &simpleLoginAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -549,7 +549,7 @@ func TestLoginWithHTTPErr(t *testing.T) {
func TestLoginMarshalErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &LoginAPI{
api := &simpleLoginAPI{
JSONCodec: &FakeCodec{EncodeErr: errMocked},
}
ctx := context.Background()
@ -567,7 +567,7 @@ func TestLoginMarshalErr(t *testing.T) {
func TestLoginWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &LoginAPI{
api := &simpleLoginAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -585,7 +585,7 @@ func TestLoginWithNewRequestErr(t *testing.T) {
func TestLoginWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &LoginAPI{
api := &simpleLoginAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -603,7 +603,7 @@ func TestLoginWith401(t *testing.T) {
func TestLoginWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &LoginAPI{
api := &simpleLoginAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -625,7 +625,7 @@ func TestLoginWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &LoginAPI{
api := &simpleLoginAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -647,7 +647,7 @@ func TestLoginWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &LoginAPI{
api := &simpleLoginAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -717,7 +717,7 @@ func TestLoginRoundTrip(t *testing.T) {
req := &apimodel.LoginRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &LoginAPI{BaseURL: srvr.URL}
api := &simpleLoginAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -757,7 +757,7 @@ func TestLoginRoundTrip(t *testing.T) {
}
func TestMeasurementMetaInvalidURL(t *testing.T) {
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -776,7 +776,7 @@ func TestMeasurementMetaInvalidURL(t *testing.T) {
func TestMeasurementMetaWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -794,7 +794,7 @@ func TestMeasurementMetaWithHTTPErr(t *testing.T) {
func TestMeasurementMetaWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -812,7 +812,7 @@ func TestMeasurementMetaWithNewRequestErr(t *testing.T) {
func TestMeasurementMetaWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -830,7 +830,7 @@ func TestMeasurementMetaWith401(t *testing.T) {
func TestMeasurementMetaWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -852,7 +852,7 @@ func TestMeasurementMetaWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -874,7 +874,7 @@ func TestMeasurementMetaWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -944,7 +944,7 @@ func TestMeasurementMetaRoundTrip(t *testing.T) {
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &MeasurementMetaAPI{BaseURL: srvr.URL}
api := &simpleMeasurementMetaAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -987,7 +987,7 @@ func TestMeasurementMetaMandatoryFields(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{
StatusCode: 500,
}}
api := &MeasurementMetaAPI{
api := &simpleMeasurementMetaAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1002,7 +1002,7 @@ func TestMeasurementMetaMandatoryFields(t *testing.T) {
}
func TestRegisterInvalidURL(t *testing.T) {
api := &RegisterAPI{
api := &simpleRegisterAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -1021,7 +1021,7 @@ func TestRegisterInvalidURL(t *testing.T) {
func TestRegisterWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &RegisterAPI{
api := &simpleRegisterAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1039,7 +1039,7 @@ func TestRegisterWithHTTPErr(t *testing.T) {
func TestRegisterMarshalErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &RegisterAPI{
api := &simpleRegisterAPI{
JSONCodec: &FakeCodec{EncodeErr: errMocked},
}
ctx := context.Background()
@ -1057,7 +1057,7 @@ func TestRegisterMarshalErr(t *testing.T) {
func TestRegisterWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &RegisterAPI{
api := &simpleRegisterAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -1075,7 +1075,7 @@ func TestRegisterWithNewRequestErr(t *testing.T) {
func TestRegisterWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &RegisterAPI{
api := &simpleRegisterAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1093,7 +1093,7 @@ func TestRegisterWith401(t *testing.T) {
func TestRegisterWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &RegisterAPI{
api := &simpleRegisterAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1115,7 +1115,7 @@ func TestRegisterWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &RegisterAPI{
api := &simpleRegisterAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1137,7 +1137,7 @@ func TestRegisterWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &RegisterAPI{
api := &simpleRegisterAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -1207,7 +1207,7 @@ func TestRegisterRoundTrip(t *testing.T) {
req := &apimodel.RegisterRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &RegisterAPI{BaseURL: srvr.URL}
api := &simpleRegisterAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -1247,7 +1247,7 @@ func TestRegisterRoundTrip(t *testing.T) {
}
func TestTestHelpersInvalidURL(t *testing.T) {
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -1266,7 +1266,7 @@ func TestTestHelpersInvalidURL(t *testing.T) {
func TestTestHelpersWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1284,7 +1284,7 @@ func TestTestHelpersWithHTTPErr(t *testing.T) {
func TestTestHelpersWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -1302,7 +1302,7 @@ func TestTestHelpersWithNewRequestErr(t *testing.T) {
func TestTestHelpersWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1320,7 +1320,7 @@ func TestTestHelpersWith401(t *testing.T) {
func TestTestHelpersWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1342,7 +1342,7 @@ func TestTestHelpersWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1364,7 +1364,7 @@ func TestTestHelpersWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -1434,7 +1434,7 @@ func TestTestHelpersRoundTrip(t *testing.T) {
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &TestHelpersAPI{BaseURL: srvr.URL}
api := &simpleTestHelpersAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -1478,7 +1478,7 @@ func TestTestHelpersResponseLiteralNull(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`null`)},
}}
api := &TestHelpersAPI{
api := &simpleTestHelpersAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -1495,7 +1495,7 @@ func TestTestHelpersResponseLiteralNull(t *testing.T) {
}
func TestPsiphonConfigInvalidURL(t *testing.T) {
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -1512,7 +1512,7 @@ func TestPsiphonConfigInvalidURL(t *testing.T) {
}
func TestPsiphonConfigWithMissingToken(t *testing.T) {
api := &PsiphonConfigAPI{} // no token
api := &simplePsiphonConfigAPI{} // no token
ctx := context.Background()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
@ -1529,7 +1529,7 @@ func TestPsiphonConfigWithMissingToken(t *testing.T) {
func TestPsiphonConfigWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1548,7 +1548,7 @@ func TestPsiphonConfigWithHTTPErr(t *testing.T) {
func TestPsiphonConfigWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
Token: "fakeToken",
}
@ -1567,7 +1567,7 @@ func TestPsiphonConfigWithNewRequestErr(t *testing.T) {
func TestPsiphonConfigWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1586,7 +1586,7 @@ func TestPsiphonConfigWith401(t *testing.T) {
func TestPsiphonConfigWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1609,7 +1609,7 @@ func TestPsiphonConfigWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1632,7 +1632,7 @@ func TestPsiphonConfigWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
Token: "fakeToken",
@ -1703,7 +1703,7 @@ func TestPsiphonConfigRoundTrip(t *testing.T) {
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &PsiphonConfigAPI{BaseURL: srvr.URL}
api := &simplePsiphonConfigAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.fill(&api.Token)
// issue request
@ -1748,7 +1748,7 @@ func TestPsiphonConfigResponseLiteralNull(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`null`)},
}}
api := &PsiphonConfigAPI{
api := &simplePsiphonConfigAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1766,7 +1766,7 @@ func TestPsiphonConfigResponseLiteralNull(t *testing.T) {
}
func TestTorTargetsInvalidURL(t *testing.T) {
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -1783,7 +1783,7 @@ func TestTorTargetsInvalidURL(t *testing.T) {
}
func TestTorTargetsWithMissingToken(t *testing.T) {
api := &TorTargetsAPI{} // no token
api := &simpleTorTargetsAPI{} // no token
ctx := context.Background()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
@ -1800,7 +1800,7 @@ func TestTorTargetsWithMissingToken(t *testing.T) {
func TestTorTargetsWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1819,7 +1819,7 @@ func TestTorTargetsWithHTTPErr(t *testing.T) {
func TestTorTargetsWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
Token: "fakeToken",
}
@ -1838,7 +1838,7 @@ func TestTorTargetsWithNewRequestErr(t *testing.T) {
func TestTorTargetsWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1857,7 +1857,7 @@ func TestTorTargetsWith401(t *testing.T) {
func TestTorTargetsWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1880,7 +1880,7 @@ func TestTorTargetsWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -1903,7 +1903,7 @@ func TestTorTargetsWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
Token: "fakeToken",
@ -1974,7 +1974,7 @@ func TestTorTargetsRoundTrip(t *testing.T) {
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &TorTargetsAPI{BaseURL: srvr.URL}
api := &simpleTorTargetsAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
ff.fill(&api.Token)
// issue request
@ -2019,7 +2019,7 @@ func TestTorTargetsResponseLiteralNull(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`null`)},
}}
api := &TorTargetsAPI{
api := &simpleTorTargetsAPI{
HTTPClient: clnt,
Token: "fakeToken",
}
@ -2037,7 +2037,7 @@ func TestTorTargetsResponseLiteralNull(t *testing.T) {
}
func TestURLsInvalidURL(t *testing.T) {
api := &URLsAPI{
api := &simpleURLsAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -2056,7 +2056,7 @@ func TestURLsInvalidURL(t *testing.T) {
func TestURLsWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &URLsAPI{
api := &simpleURLsAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2074,7 +2074,7 @@ func TestURLsWithHTTPErr(t *testing.T) {
func TestURLsWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &URLsAPI{
api := &simpleURLsAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -2092,7 +2092,7 @@ func TestURLsWithNewRequestErr(t *testing.T) {
func TestURLsWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &URLsAPI{
api := &simpleURLsAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2110,7 +2110,7 @@ func TestURLsWith401(t *testing.T) {
func TestURLsWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &URLsAPI{
api := &simpleURLsAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2132,7 +2132,7 @@ func TestURLsWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &URLsAPI{
api := &simpleURLsAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2154,7 +2154,7 @@ func TestURLsWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &URLsAPI{
api := &simpleURLsAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -2224,7 +2224,7 @@ func TestURLsRoundTrip(t *testing.T) {
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &URLsAPI{BaseURL: srvr.URL}
api := &simpleURLsAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -2264,7 +2264,7 @@ func TestURLsRoundTrip(t *testing.T) {
}
func TestOpenReportInvalidURL(t *testing.T) {
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -2283,7 +2283,7 @@ func TestOpenReportInvalidURL(t *testing.T) {
func TestOpenReportWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2301,7 +2301,7 @@ func TestOpenReportWithHTTPErr(t *testing.T) {
func TestOpenReportMarshalErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
JSONCodec: &FakeCodec{EncodeErr: errMocked},
}
ctx := context.Background()
@ -2319,7 +2319,7 @@ func TestOpenReportMarshalErr(t *testing.T) {
func TestOpenReportWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -2337,7 +2337,7 @@ func TestOpenReportWithNewRequestErr(t *testing.T) {
func TestOpenReportWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2355,7 +2355,7 @@ func TestOpenReportWith401(t *testing.T) {
func TestOpenReportWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2377,7 +2377,7 @@ func TestOpenReportWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2399,7 +2399,7 @@ func TestOpenReportWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &OpenReportAPI{
api := &simpleOpenReportAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -2469,7 +2469,7 @@ func TestOpenReportRoundTrip(t *testing.T) {
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &OpenReportAPI{BaseURL: srvr.URL}
api := &simpleOpenReportAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -2509,7 +2509,7 @@ func TestOpenReportRoundTrip(t *testing.T) {
}
func TestSubmitMeasurementInvalidURL(t *testing.T) {
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
BaseURL: "\t", // invalid
}
ctx := context.Background()
@ -2528,7 +2528,7 @@ func TestSubmitMeasurementInvalidURL(t *testing.T) {
func TestSubmitMeasurementWithHTTPErr(t *testing.T) {
errMocked := errors.New("mocked error")
clnt := &FakeHTTPClient{Err: errMocked}
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2546,7 +2546,7 @@ func TestSubmitMeasurementWithHTTPErr(t *testing.T) {
func TestSubmitMeasurementMarshalErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
JSONCodec: &FakeCodec{EncodeErr: errMocked},
}
ctx := context.Background()
@ -2564,7 +2564,7 @@ func TestSubmitMeasurementMarshalErr(t *testing.T) {
func TestSubmitMeasurementWithNewRequestErr(t *testing.T) {
errMocked := errors.New("mocked error")
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
RequestMaker: &FakeRequestMaker{Err: errMocked},
}
ctx := context.Background()
@ -2582,7 +2582,7 @@ func TestSubmitMeasurementWithNewRequestErr(t *testing.T) {
func TestSubmitMeasurementWith401(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 401}}
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2600,7 +2600,7 @@ func TestSubmitMeasurementWith401(t *testing.T) {
func TestSubmitMeasurementWith400(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{StatusCode: 400}}
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2622,7 +2622,7 @@ func TestSubmitMeasurementWithResponseBodyReadErr(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Err: errMocked},
}}
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
HTTPClient: clnt,
}
ctx := context.Background()
@ -2644,7 +2644,7 @@ func TestSubmitMeasurementWithUnmarshalFailure(t *testing.T) {
StatusCode: 200,
Body: &FakeBody{Data: []byte(`{}`)},
}}
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
HTTPClient: clnt,
JSONCodec: &FakeCodec{DecodeErr: errMocked},
}
@ -2714,7 +2714,7 @@ func TestSubmitMeasurementRoundTrip(t *testing.T) {
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(&req)
api := &SubmitMeasurementAPI{BaseURL: srvr.URL}
api := &simpleSubmitMeasurementAPI{BaseURL: srvr.URL}
ff.fill(&api.UserAgent)
// issue request
ctx := context.Background()
@ -2758,7 +2758,7 @@ func TestSubmitMeasurementTemplateErr(t *testing.T) {
clnt := &FakeHTTPClient{Resp: &http.Response{
StatusCode: 500,
}}
api := &SubmitMeasurementAPI{
api := &simpleSubmitMeasurementAPI{
HTTPClient: clnt,
TemplateExecutor: &FakeTemplateExecutor{Err: errMocked},
}