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: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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue