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
parent eed51978ca
commit 93f084598e
24 changed files with 433 additions and 337 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:55.762084 +0200 CEST m=+0.000209251
// 2022-01-04 17:58:20.329834948 +0100 CET m=+0.000081946
package ooapi
+124 -124
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)
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:56.387017 +0200 CEST m=+0.000215293
// 2022-01-04 17:58:21.763824725 +0100 CET m=+0.000091434
package ooapi
+16 -16
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:56.679306 +0200 CEST m=+0.000207960
// 2022-01-04 17:58:22.460760999 +0100 CET m=+0.000133744
package ooapi
@@ -18,7 +18,7 @@ import (
func TestCachesimpleMeasurementMetaAPISuccess(t *testing.T) {
ff := &fakeFill{}
var expect *apimodel.MeasurementMetaResponse
ff.fill(&expect)
ff.Fill(&expect)
cache := &withCacheMeasurementMetaAPI{
API: &FakeMeasurementMetaAPI{
Response: expect,
@@ -26,7 +26,7 @@ func TestCachesimpleMeasurementMetaAPISuccess(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := cache.Call(ctx, req)
if err != nil {
@@ -44,7 +44,7 @@ func TestCachesimpleMeasurementMetaAPIWriteCacheError(t *testing.T) {
errMocked := errors.New("mocked error")
ff := &fakeFill{}
var expect *apimodel.MeasurementMetaResponse
ff.fill(&expect)
ff.Fill(&expect)
cache := &withCacheMeasurementMetaAPI{
API: &FakeMeasurementMetaAPI{
Response: expect,
@@ -52,7 +52,7 @@ func TestCachesimpleMeasurementMetaAPIWriteCacheError(t *testing.T) {
KVStore: &FakeKVStore{SetError: errMocked},
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := cache.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -73,7 +73,7 @@ func TestCachesimpleMeasurementMetaAPIFailureWithNoCache(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := cache.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -87,7 +87,7 @@ func TestCachesimpleMeasurementMetaAPIFailureWithNoCache(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIFailureWithPreviousCache(t *testing.T) {
ff := &fakeFill{}
var expect *apimodel.MeasurementMetaResponse
ff.fill(&expect)
ff.Fill(&expect)
fakeapi := &FakeMeasurementMetaAPI{
Response: expect,
}
@@ -96,7 +96,7 @@ func TestCachesimpleMeasurementMetaAPIFailureWithPreviousCache(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// first pass with no error at all
// use a separate scope to be sure we avoid mistakes
@@ -132,7 +132,7 @@ func TestCachesimpleMeasurementMetaAPISetcacheWithEncodeError(t *testing.T) {
ff := &fakeFill{}
errMocked := errors.New("mocked error")
var in []cacheEntryForMeasurementMetaAPI
ff.fill(&in)
ff.Fill(&in)
cache := &withCacheMeasurementMetaAPI{
GobCodec: &FakeCodec{EncodeErr: errMocked},
}
@@ -145,7 +145,7 @@ func TestCachesimpleMeasurementMetaAPISetcacheWithEncodeError(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIReadCacheNotFound(t *testing.T) {
ff := &fakeFill{}
var incache []cacheEntryForMeasurementMetaAPI
ff.fill(&incache)
ff.Fill(&incache)
cache := &withCacheMeasurementMetaAPI{
KVStore: &kvstore.Memory{},
}
@@ -154,7 +154,7 @@ func TestCachesimpleMeasurementMetaAPIReadCacheNotFound(t *testing.T) {
t.Fatal(err)
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
ff.Fill(&req)
out, err := cache.readcache(req)
if !errors.Is(err, errCacheNotFound) {
t.Fatal("not the error we expected", err)
@@ -167,11 +167,11 @@ func TestCachesimpleMeasurementMetaAPIReadCacheNotFound(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIWriteCacheDuplicate(t *testing.T) {
ff := &fakeFill{}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
ff.Fill(&req)
var resp1 *apimodel.MeasurementMetaResponse
ff.fill(&resp1)
ff.Fill(&resp1)
var resp2 *apimodel.MeasurementMetaResponse
ff.fill(&resp2)
ff.Fill(&resp2)
cache := &withCacheMeasurementMetaAPI{
KVStore: &kvstore.Memory{},
}
@@ -203,9 +203,9 @@ func TestCachesimpleMeasurementMetaAPICacheSizeLimited(t *testing.T) {
var prev int
for {
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
ff.Fill(&req)
var resp *apimodel.MeasurementMetaResponse
ff.fill(&resp)
ff.Fill(&resp)
err := cache.writecache(req, resp)
if err != nil {
t.Fatal(err)
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:56.962776 +0200 CEST m=+0.000233959
// 2022-01-04 17:58:22.981823549 +0100 CET m=+0.000269410
package ooapi
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:57.244698 +0200 CEST m=+0.000236459
// 2022-01-04 17:58:23.476477599 +0100 CET m=+0.000137872
package ooapi
+32 -32
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:57.571045 +0200 CEST m=+0.000218459
// 2022-01-04 17:58:23.995454536 +0100 CET m=+0.000235066
package ooapi
@@ -55,7 +55,7 @@ func (h *handleClientCallCheckReportID) ServeHTTP(w http.ResponseWriter, r *http
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.CheckReportIDResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -72,9 +72,9 @@ func TestCheckReportIDClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.CheckReportIDRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.CheckReportID(ctx, req)
@@ -148,7 +148,7 @@ func (h *handleClientCallCheckIn) ServeHTTP(w http.ResponseWriter, r *http.Reque
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.CheckInResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -165,9 +165,9 @@ func TestCheckInClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.CheckInRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.CheckIn(ctx, req)
@@ -240,7 +240,7 @@ func (h *handleClientCallMeasurementMeta) ServeHTTP(w http.ResponseWriter, r *ht
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.MeasurementMetaResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -257,9 +257,9 @@ func TestMeasurementMetaClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.MeasurementMetaRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.MeasurementMeta(ctx, req)
@@ -333,7 +333,7 @@ func (h *handleClientCallTestHelpers) ServeHTTP(w http.ResponseWriter, r *http.R
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out apimodel.TestHelpersResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -350,9 +350,9 @@ func TestTestHelpersClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.TestHelpersRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.TestHelpers(ctx, req)
@@ -407,7 +407,7 @@ func (h *handleClientCallPsiphonConfig) ServeHTTP(w http.ResponseWriter, r *http
ff := fakeFill{}
if r.URL.Path == "/api/v1/register" {
var out apimodel.RegisterResponse
ff.fill(&out)
ff.Fill(&out)
data, err := json.Marshal(out)
if err != nil {
w.WriteHeader(400)
@@ -418,7 +418,7 @@ func (h *handleClientCallPsiphonConfig) ServeHTTP(w http.ResponseWriter, r *http
}
if r.URL.Path == "/api/v1/login" {
var out apimodel.LoginResponse
ff.fill(&out)
ff.Fill(&out)
data, err := json.Marshal(out)
if err != nil {
w.WriteHeader(400)
@@ -448,7 +448,7 @@ func (h *handleClientCallPsiphonConfig) ServeHTTP(w http.ResponseWriter, r *http
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out apimodel.PsiphonConfigResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -465,9 +465,9 @@ func TestPsiphonConfigClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.PsiphonConfigRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.PsiphonConfig(ctx, req)
@@ -522,7 +522,7 @@ func (h *handleClientCallTorTargets) ServeHTTP(w http.ResponseWriter, r *http.Re
ff := fakeFill{}
if r.URL.Path == "/api/v1/register" {
var out apimodel.RegisterResponse
ff.fill(&out)
ff.Fill(&out)
data, err := json.Marshal(out)
if err != nil {
w.WriteHeader(400)
@@ -533,7 +533,7 @@ func (h *handleClientCallTorTargets) ServeHTTP(w http.ResponseWriter, r *http.Re
}
if r.URL.Path == "/api/v1/login" {
var out apimodel.LoginResponse
ff.fill(&out)
ff.Fill(&out)
data, err := json.Marshal(out)
if err != nil {
w.WriteHeader(400)
@@ -563,7 +563,7 @@ func (h *handleClientCallTorTargets) ServeHTTP(w http.ResponseWriter, r *http.Re
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out apimodel.TorTargetsResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -580,9 +580,9 @@ func TestTorTargetsClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.TorTargetsRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.TorTargets(ctx, req)
@@ -656,7 +656,7 @@ func (h *handleClientCallURLs) ServeHTTP(w http.ResponseWriter, r *http.Request)
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.URLsResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -673,9 +673,9 @@ func TestURLsClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.URLsRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.URLs(ctx, req)
@@ -749,7 +749,7 @@ func (h *handleClientCallOpenReport) ServeHTTP(w http.ResponseWriter, r *http.Re
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.OpenReportResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -766,9 +766,9 @@ func TestOpenReportClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.OpenReportRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.OpenReport(ctx, req)
@@ -841,7 +841,7 @@ func (h *handleClientCallSubmitMeasurement) ServeHTTP(w http.ResponseWriter, r *
h.contentType = r.Header.Get("Content-Type")
h.userAgent = r.Header.Get("User-Agent")
var out *apimodel.SubmitMeasurementResponse
ff.fill(&out)
ff.Fill(&out)
h.resp = out
data, err := json.Marshal(out)
if err != nil {
@@ -858,9 +858,9 @@ func TestSubmitMeasurementClientCallRoundTrip(t *testing.T) {
defer srvr.Close()
req := &apimodel.SubmitMeasurementRequest{}
ff := &fakeFill{}
ff.fill(&req)
ff.Fill(&req)
clnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}
ff.fill(&clnt.UserAgent)
ff.Fill(&clnt.UserAgent)
// issue request
ctx := context.Background()
resp, err := clnt.SubmitMeasurement(ctx, req)
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:57.8828 +0200 CEST m=+0.000181501
// 2022-01-04 17:58:24.519577773 +0100 CET m=+0.000226600
package ooapi
+4
View File
@@ -6,9 +6,13 @@ import (
"net/http"
"time"
"github.com/ooni/probe-cli/v3/internal/fakefill"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// fakeFill forwards the fakefill.Filler type
type fakeFill = fakefill.Filler
type FakeCodec struct {
DecodeErr error
EncodeData []byte
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:58.154461 +0200 CEST m=+0.000196126
// 2022-01-04 17:58:24.965043633 +0100 CET m=+0.000133804
package ooapi
-146
View File
@@ -1,146 +0,0 @@
package ooapi
import (
"math/rand"
"reflect"
"sync"
"testing"
"time"
"github.com/ooni/probe-cli/v3/internal/ooapi/apimodel"
)
// fakeFill fills specific data structures with random data. The only
// exception to this behaviour is time.Time, which is instead filled
// with the current time plus a small random number of seconds.
//
// We use this implementation to initialize data in our model. The code
// has been written with that in mind. It will require some hammering in
// case we extend the model with new field types.
type fakeFill struct {
mu sync.Mutex
now func() time.Time
rnd *rand.Rand
}
func (ff *fakeFill) getRandLocked() *rand.Rand {
if ff.rnd == nil {
now := time.Now
if ff.now != nil {
now = ff.now
}
ff.rnd = rand.New(rand.NewSource(now().UnixNano()))
}
return ff.rnd
}
func (ff *fakeFill) getRandomString() string {
defer ff.mu.Unlock()
ff.mu.Lock()
rnd := ff.getRandLocked()
n := rnd.Intn(63) + 1
// See https://stackoverflow.com/a/31832326
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rnd.Intn(len(letterRunes))]
}
return string(b)
}
func (ff *fakeFill) getRandomInt64() int64 {
defer ff.mu.Unlock()
ff.mu.Lock()
rnd := ff.getRandLocked()
return rnd.Int63()
}
func (ff *fakeFill) getRandomBool() bool {
defer ff.mu.Unlock()
ff.mu.Lock()
rnd := ff.getRandLocked()
return rnd.Float64() >= 0.5
}
func (ff *fakeFill) getRandomSmallPositiveInt() int {
defer ff.mu.Unlock()
ff.mu.Lock()
rnd := ff.getRandLocked()
return int(rnd.Int63n(8)) + 1 // safe cast
}
func (ff *fakeFill) doFill(v reflect.Value) {
for v.Type().Kind() == reflect.Ptr {
if v.IsNil() {
// if the pointer is nil, allocate an element
v.Set(reflect.New(v.Type().Elem()))
}
// switch to the element
v = v.Elem()
}
switch v.Type().Kind() {
case reflect.String:
v.SetString(ff.getRandomString())
case reflect.Int64:
v.SetInt(ff.getRandomInt64())
case reflect.Bool:
v.SetBool(ff.getRandomBool())
case reflect.Struct:
if v.Type().String() == "time.Time" {
// Implementation note: we treat the time specially
// and we avoid attempting to set its fields.
v.Set(reflect.ValueOf(time.Now().Add(
time.Duration(ff.getRandomSmallPositiveInt()) * time.Second)))
return
}
for idx := 0; idx < v.NumField(); idx++ {
ff.doFill(v.Field(idx)) // visit all fields
}
case reflect.Slice:
kind := v.Type().Elem()
total := ff.getRandomSmallPositiveInt()
for idx := 0; idx < total; idx++ {
value := reflect.New(kind) // make a new element
ff.doFill(value)
v.Set(reflect.Append(v, value.Elem())) // append to slice
}
case reflect.Map:
if v.Type().Key().Kind() != reflect.String {
return // not supported
}
v.Set(reflect.MakeMap(v.Type())) // we need to init the map
total := ff.getRandomSmallPositiveInt()
kind := v.Type().Elem()
for idx := 0; idx < total; idx++ {
value := reflect.New(kind)
ff.doFill(value)
v.SetMapIndex(reflect.ValueOf(ff.getRandomString()), value.Elem())
}
}
}
// fill fills in with random data.
func (ff *fakeFill) fill(in interface{}) {
ff.doFill(reflect.ValueOf(in))
}
func TestFakeFillAllocatesIntoAPointerToPointer(t *testing.T) {
var req *apimodel.URLsRequest
ff := &fakeFill{}
ff.fill(&req)
if req == nil {
t.Fatal("we expected non nil here")
}
}
func TestFakeFillAllocatesIntoAMapLike(t *testing.T) {
var resp apimodel.TorTargetsResponse
ff := &fakeFill{}
ff.fill(&resp)
if resp == nil {
t.Fatal("we expected non nil here")
}
if len(resp) < 1 {
t.Fatal("we expected some data here")
}
}
@@ -10,7 +10,7 @@ import (
func (d *Descriptor) genTestNewRequest(sb *strings.Builder) {
fmt.Fprintf(sb, "\treq := &%s{}\n", d.RequestTypeNameAsStruct())
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprint(sb, "\tff.fill(req)\n")
fmt.Fprint(sb, "\tff.Fill(req)\n")
}
func (d *Descriptor) genTestInvalidURL(sb *strings.Builder) {
@@ -245,7 +245,7 @@ func (d *Descriptor) genTestRoundTrip(sb *strings.Builder) {
fmt.Fprint(sb, "\th.userAgent = r.Header.Get(\"User-Agent\")\n")
fmt.Fprintf(sb, "\tvar out %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff := fakeFill{}\n")
fmt.Fprint(sb, "\tff.fill(&out)\n")
fmt.Fprint(sb, "\tff.Fill(&out)\n")
fmt.Fprintf(sb, "\th.resp = out\n")
fmt.Fprintf(sb, "\tdata, err := json.Marshal(out)\n")
fmt.Fprintf(sb, "\tif err != nil {\n")
@@ -264,11 +264,11 @@ func (d *Descriptor) genTestRoundTrip(sb *strings.Builder) {
fmt.Fprint(sb, "\tdefer srvr.Close()\n")
fmt.Fprintf(sb, "\treq := &%s{}\n", d.RequestTypeNameAsStruct())
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprintf(sb, "\tapi := &%s{BaseURL: srvr.URL}\n", d.APIStructName())
fmt.Fprint(sb, "\tff.fill(&api.UserAgent)\n")
fmt.Fprint(sb, "\tff.Fill(&api.UserAgent)\n")
if d.RequiresLogin {
fmt.Fprint(sb, "\tff.fill(&api.Token)\n")
fmt.Fprint(sb, "\tff.Fill(&api.Token)\n")
}
fmt.Fprint(sb, "\t// issue request\n")
@@ -10,7 +10,7 @@ func (d *Descriptor) genTestCacheSuccess(sb *strings.Builder) {
fmt.Fprintf(sb, "func TestCache%sSuccess(t *testing.T) {\n", d.APIStructName())
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprintf(sb, "\tcache := &%s{\n", d.WithCacheAPIStructName())
fmt.Fprintf(sb, "\t\tAPI: &%s{\n", d.FakeAPIStructName())
fmt.Fprint(sb, "\t\t\tResponse: expect,\n")
@@ -18,7 +18,7 @@ func (d *Descriptor) genTestCacheSuccess(sb *strings.Builder) {
fmt.Fprint(sb, "\t\tKVStore: &kvstore.Memory{},\n")
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := cache.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif err != nil {\n")
@@ -38,7 +38,7 @@ func (d *Descriptor) genTestWriteCacheError(sb *strings.Builder) {
fmt.Fprint(sb, "\terrMocked := errors.New(\"mocked error\")\n")
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprintf(sb, "\tcache := &%s{\n", d.WithCacheAPIStructName())
fmt.Fprintf(sb, "\t\tAPI: &%s{\n", d.FakeAPIStructName())
fmt.Fprint(sb, "\t\t\tResponse: expect,\n")
@@ -46,7 +46,7 @@ func (d *Descriptor) genTestWriteCacheError(sb *strings.Builder) {
fmt.Fprint(sb, "\t\tKVStore: &FakeKVStore{SetError: errMocked},\n")
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := cache.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif !errors.Is(err, errMocked) {\n")
@@ -69,7 +69,7 @@ func (d *Descriptor) genTestFailureWithNoCache(sb *strings.Builder) {
fmt.Fprint(sb, "\t\tKVStore: &kvstore.Memory{},\n")
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := cache.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif !errors.Is(err, errMocked) {\n")
@@ -86,7 +86,7 @@ func (d *Descriptor) genTestFailureWithPreviousCache(sb *strings.Builder) {
fmt.Fprintf(sb, "func TestCache%sFailureWithPreviousCache(t *testing.T) {\n", d.APIStructName())
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprintf(sb, "\tfakeapi := &%s{\n", d.FakeAPIStructName())
fmt.Fprint(sb, "\t\tResponse: expect,\n")
fmt.Fprint(sb, "\t}\n")
@@ -95,7 +95,7 @@ func (d *Descriptor) genTestFailureWithPreviousCache(sb *strings.Builder) {
fmt.Fprint(sb, "\t\tKVStore: &kvstore.Memory{},\n")
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\t// first pass with no error at all\n")
fmt.Fprint(sb, "\t// use a separate scope to be sure we avoid mistakes\n")
@@ -133,7 +133,7 @@ func (d *Descriptor) genTestSetcacheWithEncodeError(sb *strings.Builder) {
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprint(sb, "\terrMocked := errors.New(\"mocked error\")\n")
fmt.Fprintf(sb, "\tvar in []%s\n", d.CacheEntryName())
fmt.Fprint(sb, "\tff.fill(&in)\n")
fmt.Fprint(sb, "\tff.Fill(&in)\n")
fmt.Fprintf(sb, "\tcache := &%s{\n", d.WithCacheAPIStructName())
fmt.Fprint(sb, "\t\tGobCodec: &FakeCodec{EncodeErr: errMocked},\n")
fmt.Fprint(sb, "\t}\n")
@@ -154,7 +154,7 @@ func (d *Descriptor) genTestReadCacheNotFound(sb *strings.Builder) {
fmt.Fprintf(sb, "func TestCache%sReadCacheNotFound(t *testing.T) {\n", d.APIStructName())
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar incache []%s\n", d.CacheEntryName())
fmt.Fprint(sb, "\tff.fill(&incache)\n")
fmt.Fprint(sb, "\tff.Fill(&incache)\n")
fmt.Fprintf(sb, "\tcache := &%s{\n", d.WithCacheAPIStructName())
fmt.Fprint(sb, "\t\tKVStore: &kvstore.Memory{},\n")
fmt.Fprint(sb, "\t}\n")
@@ -163,7 +163,7 @@ func (d *Descriptor) genTestReadCacheNotFound(sb *strings.Builder) {
fmt.Fprintf(sb, "\t\tt.Fatal(err)\n")
fmt.Fprintf(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprintf(sb, "\tout, err := cache.readcache(req)\n")
fmt.Fprint(sb, "\tif !errors.Is(err, errCacheNotFound) {\n")
fmt.Fprint(sb, "\t\tt.Fatal(\"not the error we expected\", err)\n")
@@ -178,11 +178,11 @@ func (d *Descriptor) genTestWriteCacheDuplicate(sb *strings.Builder) {
fmt.Fprintf(sb, "func TestCache%sWriteCacheDuplicate(t *testing.T) {\n", d.APIStructName())
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprintf(sb, "\tvar resp1 %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&resp1)\n")
fmt.Fprint(sb, "\tff.Fill(&resp1)\n")
fmt.Fprintf(sb, "\tvar resp2 %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&resp2)\n")
fmt.Fprint(sb, "\tff.Fill(&resp2)\n")
fmt.Fprintf(sb, "\tcache := &%s{\n", d.WithCacheAPIStructName())
fmt.Fprint(sb, "\t\tKVStore: &kvstore.Memory{},\n")
fmt.Fprint(sb, "\t}\n")
@@ -222,9 +222,9 @@ func (d *Descriptor) genTestCachSizeLimited(sb *strings.Builder) {
fmt.Fprintf(sb, "\tvar prev int\n")
fmt.Fprintf(sb, "\tfor {\n")
fmt.Fprintf(sb, "\t\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\t\tff.fill(&req)\n")
fmt.Fprint(sb, "\t\tff.Fill(&req)\n")
fmt.Fprintf(sb, "\t\tvar resp %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\t\tff.fill(&resp)\n")
fmt.Fprint(sb, "\t\tff.Fill(&resp)\n")
fmt.Fprintf(sb, "\t\terr := cache.writecache(req, resp)\n")
fmt.Fprintf(sb, "\t\tif err != nil {\n")
fmt.Fprintf(sb, "\t\t\tt.Fatal(err)\n")
@@ -28,7 +28,7 @@ func (d *Descriptor) genTestClientCallRoundTrip(sb *strings.Builder) {
if d.RequiresLogin {
fmt.Fprintf(sb, "\tif r.URL.Path == \"/api/v1/register\" {\n")
fmt.Fprintf(sb, "\t\tvar out apimodel.RegisterResponse\n")
fmt.Fprintf(sb, "\t\tff.fill(&out)\n")
fmt.Fprintf(sb, "\t\tff.Fill(&out)\n")
fmt.Fprintf(sb, "\t\tdata, err := json.Marshal(out)\n")
fmt.Fprintf(sb, "\t\tif err != nil {\n")
fmt.Fprintf(sb, "\t\t\tw.WriteHeader(400)\n")
@@ -39,7 +39,7 @@ func (d *Descriptor) genTestClientCallRoundTrip(sb *strings.Builder) {
fmt.Fprintf(sb, "\t}\n")
fmt.Fprintf(sb, "\tif r.URL.Path == \"/api/v1/login\" {\n")
fmt.Fprintf(sb, "\t\tvar out apimodel.LoginResponse\n")
fmt.Fprintf(sb, "\t\tff.fill(&out)\n")
fmt.Fprintf(sb, "\t\tff.Fill(&out)\n")
fmt.Fprintf(sb, "\t\tdata, err := json.Marshal(out)\n")
fmt.Fprintf(sb, "\t\tif err != nil {\n")
fmt.Fprintf(sb, "\t\t\tw.WriteHeader(400)\n")
@@ -70,7 +70,7 @@ func (d *Descriptor) genTestClientCallRoundTrip(sb *strings.Builder) {
fmt.Fprint(sb, "\th.contentType = r.Header.Get(\"Content-Type\")\n")
fmt.Fprint(sb, "\th.userAgent = r.Header.Get(\"User-Agent\")\n")
fmt.Fprintf(sb, "\tvar out %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&out)\n")
fmt.Fprint(sb, "\tff.Fill(&out)\n")
fmt.Fprintf(sb, "\th.resp = out\n")
fmt.Fprintf(sb, "\tdata, err := json.Marshal(out)\n")
fmt.Fprintf(sb, "\tif err != nil {\n")
@@ -89,9 +89,9 @@ func (d *Descriptor) genTestClientCallRoundTrip(sb *strings.Builder) {
fmt.Fprint(sb, "\tdefer srvr.Close()\n")
fmt.Fprintf(sb, "\treq := &%s{}\n", d.RequestTypeNameAsStruct())
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tclnt := &Client{KVStore: &kvstore.Memory{}, BaseURL: srvr.URL}\n")
fmt.Fprint(sb, "\tff.fill(&clnt.UserAgent)\n")
fmt.Fprint(sb, "\tff.Fill(&clnt.UserAgent)\n")
fmt.Fprint(sb, "\t// issue request\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
+20 -20
View File
@@ -10,7 +10,7 @@ func (d *Descriptor) genTestRegisterAndLoginSuccess(sb *strings.Builder) {
fmt.Fprintf(sb, "func TestRegisterAndLogin%sSuccess(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\tregisterAPI := &FakeRegisterAPI{\n")
fmt.Fprint(sb, "\t\tResponse: &apimodel.RegisterResponse{\n")
@@ -39,7 +39,7 @@ func (d *Descriptor) genTestRegisterAndLoginSuccess(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := login.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif err != nil {\n")
@@ -67,7 +67,7 @@ func (d *Descriptor) genTestContinueUsingToken(sb *strings.Builder) {
fmt.Fprintf(sb, "func Test%sContinueUsingToken(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\tregisterAPI := &FakeRegisterAPI{\n")
fmt.Fprint(sb, "\t\tResponse: &apimodel.RegisterResponse{\n")
@@ -96,7 +96,7 @@ func (d *Descriptor) genTestContinueUsingToken(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\t// step 1: we register and login and use the token\n")
@@ -157,7 +157,7 @@ func (d *Descriptor) genTestWithValidButExpiredToken(sb *strings.Builder) {
fmt.Fprintf(sb, "func Test%sWithValidButExpiredToken(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\terrMocked := errors.New(\"mocked error\")\n")
fmt.Fprint(sb, "\tregisterAPI := &FakeRegisterAPI{\n")
@@ -195,7 +195,7 @@ func (d *Descriptor) genTestWithValidButExpiredToken(sb *strings.Builder) {
fmt.Fprintf(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := login.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif err != nil {\n")
@@ -223,7 +223,7 @@ func (d *Descriptor) genTestWithRegisterAPIError(sb *strings.Builder) {
fmt.Fprintf(sb, "func Test%sWithRegisterAPIError(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\terrMocked := errors.New(\"mocked error\")\n")
fmt.Fprint(sb, "\tregisterAPI := &FakeRegisterAPI{\n")
@@ -242,7 +242,7 @@ func (d *Descriptor) genTestWithRegisterAPIError(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := login.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif !errors.Is(err, errMocked) {\n")
@@ -263,7 +263,7 @@ func (d *Descriptor) genTestWithLoginFailure(sb *strings.Builder) {
fmt.Fprintf(sb, "func Test%sWithLoginFailure(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\tregisterAPI := &FakeRegisterAPI{\n")
fmt.Fprint(sb, "\t\tResponse: &apimodel.RegisterResponse{\n")
@@ -290,7 +290,7 @@ func (d *Descriptor) genTestWithLoginFailure(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := login.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif !errors.Is(err, errMocked) {\n")
@@ -315,7 +315,7 @@ func (d *Descriptor) genTestRegisterAndLoginThenFail(sb *strings.Builder) {
fmt.Fprintf(sb, "func TestRegisterAndLogin%sThenFail(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\tregisterAPI := &FakeRegisterAPI{\n")
fmt.Fprint(sb, "\t\tResponse: &apimodel.RegisterResponse{\n")
@@ -345,7 +345,7 @@ func (d *Descriptor) genTestRegisterAndLoginThenFail(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := login.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif !errors.Is(err, errMocked) {\n")
@@ -398,7 +398,7 @@ func (d *Descriptor) genTestTheDatabaseIsReplaced(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\t// step 1: we register and login and use the token\n")
@@ -476,7 +476,7 @@ func (d *Descriptor) genTestTheDatabaseIsReplacedThenFailure(sb *strings.Builder
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\t// step 1: we register and login and use the token\n")
@@ -528,7 +528,7 @@ func (d *Descriptor) genTestRegisterAndLoginCannotWriteState(sb *strings.Builder
fmt.Fprintf(sb, "func TestRegisterAndLogin%sCannotWriteState(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\tregisterAPI := &FakeRegisterAPI{\n")
fmt.Fprint(sb, "\t\tResponse: &apimodel.RegisterResponse{\n")
@@ -561,7 +561,7 @@ func (d *Descriptor) genTestRegisterAndLoginCannotWriteState(sb *strings.Builder
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\tresp, err := login.Call(ctx, req)\n")
fmt.Fprint(sb, "\tif !errors.Is(err, errMocked) {\n")
@@ -586,7 +586,7 @@ func (d *Descriptor) genTestReadStateDecodeFailure(sb *strings.Builder) {
fmt.Fprintf(sb, "func Test%sReadStateDecodeFailure(t *testing.T) {\n", d.Name)
fmt.Fprint(sb, "\tff := &fakeFill{}\n")
fmt.Fprintf(sb, "\tvar expect %s\n", d.ResponseTypeName())
fmt.Fprint(sb, "\tff.fill(&expect)\n")
fmt.Fprint(sb, "\tff.Fill(&expect)\n")
fmt.Fprint(sb, "\terrMocked := errors.New(\"mocked error\")\n")
@@ -648,7 +648,7 @@ func (d *Descriptor) genTestClockIsOffThenSuccess(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\t// step 1: we register and login and use the token\n")
@@ -728,7 +728,7 @@ func (d *Descriptor) genTestClockIsOffThen401(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\t// step 1: we register and login and use the token\n")
@@ -809,7 +809,7 @@ func (d *Descriptor) genTestClockIsOffThen500(sb *strings.Builder) {
fmt.Fprint(sb, "\t}\n")
fmt.Fprintf(sb, "\tvar req %s\n", d.RequestTypeName())
fmt.Fprint(sb, "\tff.fill(&req)\n")
fmt.Fprint(sb, "\tff.Fill(&req)\n")
fmt.Fprint(sb, "\tctx := context.Background()\n")
fmt.Fprint(sb, "\t// step 1: we register and login and use the token\n")
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:58.438865 +0200 CEST m=+0.000235709
// 2022-01-04 17:58:25.464495023 +0100 CET m=+0.000224245
package ooapi
+41 -41
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:58.734227 +0200 CEST m=+0.000193167
// 2022-01-04 17:58:25.956795743 +0100 CET m=+0.000211040
package ooapi
@@ -21,7 +21,7 @@ import (
func TestRegisterAndLoginPsiphonConfigSuccess(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -46,7 +46,7 @@ func TestRegisterAndLoginPsiphonConfigSuccess(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if err != nil {
@@ -69,7 +69,7 @@ func TestRegisterAndLoginPsiphonConfigSuccess(t *testing.T) {
func TestPsiphonConfigContinueUsingToken(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -94,7 +94,7 @@ func TestPsiphonConfigContinueUsingToken(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -144,7 +144,7 @@ func TestPsiphonConfigContinueUsingToken(t *testing.T) {
func TestPsiphonConfigWithValidButExpiredToken(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
errMocked := errors.New("mocked error")
registerAPI := &FakeRegisterAPI{
Err: errMocked,
@@ -177,7 +177,7 @@ func TestPsiphonConfigWithValidButExpiredToken(t *testing.T) {
t.Fatal(err)
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if err != nil {
@@ -200,7 +200,7 @@ func TestPsiphonConfigWithValidButExpiredToken(t *testing.T) {
func TestPsiphonConfigWithRegisterAPIError(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
errMocked := errors.New("mocked error")
registerAPI := &FakeRegisterAPI{
Err: errMocked,
@@ -216,7 +216,7 @@ func TestPsiphonConfigWithRegisterAPIError(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -233,7 +233,7 @@ func TestPsiphonConfigWithRegisterAPIError(t *testing.T) {
func TestPsiphonConfigWithLoginFailure(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -256,7 +256,7 @@ func TestPsiphonConfigWithLoginFailure(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -276,7 +276,7 @@ func TestPsiphonConfigWithLoginFailure(t *testing.T) {
func TestRegisterAndLoginPsiphonConfigThenFail(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -302,7 +302,7 @@ func TestRegisterAndLoginPsiphonConfigThenFail(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -347,7 +347,7 @@ func TestPsiphonConfigTheDatabaseIsReplaced(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -386,7 +386,7 @@ func TestPsiphonConfigTheDatabaseIsReplaced(t *testing.T) {
func TestRegisterAndLoginPsiphonConfigCannotWriteState(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -415,7 +415,7 @@ func TestRegisterAndLoginPsiphonConfigCannotWriteState(t *testing.T) {
},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -435,7 +435,7 @@ func TestRegisterAndLoginPsiphonConfigCannotWriteState(t *testing.T) {
func TestPsiphonConfigReadStateDecodeFailure(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.PsiphonConfigResponse
ff.fill(&expect)
ff.Fill(&expect)
errMocked := errors.New("mocked error")
login := &withLoginPsiphonConfigAPI{
KVStore: &kvstore.Memory{},
@@ -487,7 +487,7 @@ func TestPsiphonConfigTheDatabaseIsReplacedThenFailure(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -553,7 +553,7 @@ func TestPsiphonConfigClockIsOffThenSuccess(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -619,7 +619,7 @@ func TestPsiphonConfigClockIsOffThen401(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -686,7 +686,7 @@ func TestPsiphonConfigClockIsOffThen500(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.PsiphonConfigRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -728,7 +728,7 @@ func TestPsiphonConfigClockIsOffThen500(t *testing.T) {
func TestRegisterAndLoginTorTargetsSuccess(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -753,7 +753,7 @@ func TestRegisterAndLoginTorTargetsSuccess(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if err != nil {
@@ -776,7 +776,7 @@ func TestRegisterAndLoginTorTargetsSuccess(t *testing.T) {
func TestTorTargetsContinueUsingToken(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -801,7 +801,7 @@ func TestTorTargetsContinueUsingToken(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -851,7 +851,7 @@ func TestTorTargetsContinueUsingToken(t *testing.T) {
func TestTorTargetsWithValidButExpiredToken(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
errMocked := errors.New("mocked error")
registerAPI := &FakeRegisterAPI{
Err: errMocked,
@@ -884,7 +884,7 @@ func TestTorTargetsWithValidButExpiredToken(t *testing.T) {
t.Fatal(err)
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if err != nil {
@@ -907,7 +907,7 @@ func TestTorTargetsWithValidButExpiredToken(t *testing.T) {
func TestTorTargetsWithRegisterAPIError(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
errMocked := errors.New("mocked error")
registerAPI := &FakeRegisterAPI{
Err: errMocked,
@@ -923,7 +923,7 @@ func TestTorTargetsWithRegisterAPIError(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -940,7 +940,7 @@ func TestTorTargetsWithRegisterAPIError(t *testing.T) {
func TestTorTargetsWithLoginFailure(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -963,7 +963,7 @@ func TestTorTargetsWithLoginFailure(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -983,7 +983,7 @@ func TestTorTargetsWithLoginFailure(t *testing.T) {
func TestRegisterAndLoginTorTargetsThenFail(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -1009,7 +1009,7 @@ func TestRegisterAndLoginTorTargetsThenFail(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -1054,7 +1054,7 @@ func TestTorTargetsTheDatabaseIsReplaced(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -1093,7 +1093,7 @@ func TestTorTargetsTheDatabaseIsReplaced(t *testing.T) {
func TestRegisterAndLoginTorTargetsCannotWriteState(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
registerAPI := &FakeRegisterAPI{
Response: &apimodel.RegisterResponse{
ClientID: "antani-antani",
@@ -1122,7 +1122,7 @@ func TestRegisterAndLoginTorTargetsCannotWriteState(t *testing.T) {
},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
resp, err := login.Call(ctx, req)
if !errors.Is(err, errMocked) {
@@ -1142,7 +1142,7 @@ func TestRegisterAndLoginTorTargetsCannotWriteState(t *testing.T) {
func TestTorTargetsReadStateDecodeFailure(t *testing.T) {
ff := &fakeFill{}
var expect apimodel.TorTargetsResponse
ff.fill(&expect)
ff.Fill(&expect)
errMocked := errors.New("mocked error")
login := &withLoginTorTargetsAPI{
KVStore: &kvstore.Memory{},
@@ -1194,7 +1194,7 @@ func TestTorTargetsTheDatabaseIsReplacedThenFailure(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -1260,7 +1260,7 @@ func TestTorTargetsClockIsOffThenSuccess(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -1326,7 +1326,7 @@ func TestTorTargetsClockIsOffThen401(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
@@ -1393,7 +1393,7 @@ func TestTorTargetsClockIsOffThen500(t *testing.T) {
KVStore: &kvstore.Memory{},
}
var req *apimodel.TorTargetsRequest
ff.fill(&req)
ff.Fill(&req)
ctx := context.Background()
// step 1: we register and login and use the token
// inside a scope just to avoid mistakes
+4 -4
View File
@@ -96,7 +96,7 @@ func (lh *LoginHandler) register(w http.ResponseWriter, r *http.Request) {
}
var resp apimodel.RegisterResponse
ff := &fakeFill{}
ff.fill(&resp)
ff.Fill(&resp)
lh.state = append(lh.state, &loginState{
ClientID: resp.ClientID, Password: req.Password})
data, err = json.Marshal(&resp)
@@ -129,7 +129,7 @@ func (lh *LoginHandler) login(w http.ResponseWriter, r *http.Request) {
if req.ClientID == s.ClientID && req.Password == s.Password {
var resp apimodel.LoginResponse
ff := &fakeFill{}
ff.fill(&resp)
ff.Fill(&resp)
// We want the token to be many seconds in the future while
// ff.fill only sets the tokent to now plus a small delta.
resp.Expire = time.Now().Add(3600 * time.Second)
@@ -163,7 +163,7 @@ func (lh *LoginHandler) psiphon(w http.ResponseWriter, r *http.Request) {
if token == s.Token && time.Now().Before(s.Expire) {
var resp apimodel.PsiphonConfigResponse
ff := &fakeFill{}
ff.fill(&resp)
ff.Fill(&resp)
data, err := json.Marshal(&resp)
if err != nil {
w.WriteHeader(500)
@@ -192,7 +192,7 @@ func (lh *LoginHandler) tor(w http.ResponseWriter, r *http.Request) {
if token == s.Token && time.Now().Before(s.Expire) {
var resp apimodel.TorTargetsResponse
ff := &fakeFill{}
ff.fill(&resp)
ff.Fill(&resp)
data, err := json.Marshal(&resp)
if err != nil {
w.WriteHeader(500)
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:59.020492 +0200 CEST m=+0.000188293
// 2022-01-04 17:58:26.453995716 +0100 CET m=+0.000074291
package ooapi
+1 -1
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:59.343152 +0200 CEST m=+0.000202709
// 2022-01-04 17:58:27.025666752 +0100 CET m=+0.000120679
package ooapi
+2 -2
View File
@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-10-20 14:12:59.725759 +0200 CEST m=+0.000530042
// 2022-01-04 17:58:27.730417721 +0100 CET m=+0.001561954
package ooapi
@@ -9,7 +9,7 @@ const swagger = `{
"swagger": "2.0",
"info": {
"title": "OONI API specification",
"version": "0.20211020.10121259"
"version": "0.20220104.1165827"
},
"host": "api.ooni.io",
"basePath": "/",