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:
parent
eed51978ca
commit
93f084598e
24 changed files with 433 additions and 337 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue