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

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

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

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

* fix(ooapi): use correct comment for cloners

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

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

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

* fix(ooapi): automate copying APIs

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

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

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

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

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

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-02-26 15:45:51.49660021 +0100 CET m=+0.000217672
// 2021-03-10 13:17:32.727159555 +0100 CET m=+0.000080664
package ooapi
@ -14,15 +14,15 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/ooapi/apimodel"
)
func TestCacheMeasurementMetaAPISuccess(t *testing.T) {
func TestCachesimpleMeasurementMetaAPISuccess(t *testing.T) {
ff := &fakeFill{}
var expect *apimodel.MeasurementMetaResponse
ff.fill(&expect)
cache := &MeasurementMetaCache{
cache := &withCacheMeasurementMetaAPI{
API: &FakeMeasurementMetaAPI{
Response: expect,
},
KVStore: &memkvstore{},
KVStore: &MemKVStore{},
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
@ -39,12 +39,12 @@ func TestCacheMeasurementMetaAPISuccess(t *testing.T) {
}
}
func TestCacheMeasurementMetaAPIWriteCacheError(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIWriteCacheError(t *testing.T) {
errMocked := errors.New("mocked error")
ff := &fakeFill{}
var expect *apimodel.MeasurementMetaResponse
ff.fill(&expect)
cache := &MeasurementMetaCache{
cache := &withCacheMeasurementMetaAPI{
API: &FakeMeasurementMetaAPI{
Response: expect,
},
@ -62,14 +62,14 @@ func TestCacheMeasurementMetaAPIWriteCacheError(t *testing.T) {
}
}
func TestCacheMeasurementMetaAPIFailureWithNoCache(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIFailureWithNoCache(t *testing.T) {
errMocked := errors.New("mocked error")
ff := &fakeFill{}
cache := &MeasurementMetaCache{
cache := &withCacheMeasurementMetaAPI{
API: &FakeMeasurementMetaAPI{
Err: errMocked,
},
KVStore: &memkvstore{},
KVStore: &MemKVStore{},
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
@ -83,16 +83,16 @@ func TestCacheMeasurementMetaAPIFailureWithNoCache(t *testing.T) {
}
}
func TestCacheMeasurementMetaAPIFailureWithPreviousCache(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIFailureWithPreviousCache(t *testing.T) {
ff := &fakeFill{}
var expect *apimodel.MeasurementMetaResponse
ff.fill(&expect)
fakeapi := &FakeMeasurementMetaAPI{
Response: expect,
}
cache := &MeasurementMetaCache{
cache := &withCacheMeasurementMetaAPI{
API: fakeapi,
KVStore: &memkvstore{},
KVStore: &MemKVStore{},
}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
@ -127,12 +127,12 @@ func TestCacheMeasurementMetaAPIFailureWithPreviousCache(t *testing.T) {
}
}
func TestCacheMeasurementMetaAPISetcacheWithEncodeError(t *testing.T) {
func TestCachesimpleMeasurementMetaAPISetcacheWithEncodeError(t *testing.T) {
ff := &fakeFill{}
errMocked := errors.New("mocked error")
var in []cacheEntryForMeasurementMeta
var in []cacheEntryForMeasurementMetaAPI
ff.fill(&in)
cache := &MeasurementMetaCache{
cache := &withCacheMeasurementMetaAPI{
GobCodec: &FakeCodec{EncodeErr: errMocked},
}
err := cache.setcache(in)
@ -141,12 +141,12 @@ func TestCacheMeasurementMetaAPISetcacheWithEncodeError(t *testing.T) {
}
}
func TestCacheMeasurementMetaAPIReadCacheNotFound(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIReadCacheNotFound(t *testing.T) {
ff := &fakeFill{}
var incache []cacheEntryForMeasurementMeta
var incache []cacheEntryForMeasurementMetaAPI
ff.fill(&incache)
cache := &MeasurementMetaCache{
KVStore: &memkvstore{},
cache := &withCacheMeasurementMetaAPI{
KVStore: &MemKVStore{},
}
err := cache.setcache(incache)
if err != nil {
@ -163,7 +163,7 @@ func TestCacheMeasurementMetaAPIReadCacheNotFound(t *testing.T) {
}
}
func TestCacheMeasurementMetaAPIWriteCacheDuplicate(t *testing.T) {
func TestCachesimpleMeasurementMetaAPIWriteCacheDuplicate(t *testing.T) {
ff := &fakeFill{}
var req *apimodel.MeasurementMetaRequest
ff.fill(&req)
@ -171,8 +171,8 @@ func TestCacheMeasurementMetaAPIWriteCacheDuplicate(t *testing.T) {
ff.fill(&resp1)
var resp2 *apimodel.MeasurementMetaResponse
ff.fill(&resp2)
cache := &MeasurementMetaCache{
KVStore: &memkvstore{},
cache := &withCacheMeasurementMetaAPI{
KVStore: &MemKVStore{},
}
err := cache.writecache(req, resp1)
if err != nil {
@ -194,10 +194,10 @@ func TestCacheMeasurementMetaAPIWriteCacheDuplicate(t *testing.T) {
}
}
func TestCacheMeasurementMetaAPICacheSizeLimited(t *testing.T) {
func TestCachesimpleMeasurementMetaAPICacheSizeLimited(t *testing.T) {
ff := &fakeFill{}
cache := &MeasurementMetaCache{
KVStore: &memkvstore{},
cache := &withCacheMeasurementMetaAPI{
KVStore: &MemKVStore{},
}
var prev int
for {