refactor: interfaces and data types into the model package (#642)

## Checklist

- [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md)
- [x] reference issue for this pull request: https://github.com/ooni/probe/issues/1885
- [x] related ooni/spec pull request: N/A

Location of the issue tracker: https://github.com/ooni/probe

## Description

This PR contains a set of changes to move important interfaces and data types into the `./internal/model` package.

The criteria for including an interface or data type in here is roughly that the type should be important and used by several packages. We are especially interested to move more interfaces here to increase modularity.

An additional side effect is that, by reading this package, one should be able to understand more quickly how different parts of the codebase interact with each other.

This is what I want to move in `internal/model`:

- [x] most important interfaces from `internal/netxlite`
- [x] everything that was previously part of `internal/engine/model`
- [x] mocks from `internal/netxlite/mocks` should also be moved in here as a subpackage
This commit is contained in:
Simone Basso
2022-01-03 13:53:23 +01:00
committed by GitHub
parent 69aca619ea
commit 273b70bacc
275 changed files with 1281 additions and 1375 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
// experimentSession is the abstract representation of
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"sync"
"github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
// FakeExperimentCallbacks contains fake ExperimentCallbacks.
+10 -10
View File
@@ -11,9 +11,9 @@ import (
"github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/assetsdir"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/probeservices"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@@ -161,9 +161,9 @@ func newSessionWithContext(ctx context.Context, config *SessionConfig) (*Session
// the return value as it does not matter to us here.
_, _ = assetsdir.Cleanup(config.AssetsDir)
var availableps []model.Service
var availableps []model.OOAPIService
if config.ProbeServicesURL != "" {
availableps = append(availableps, model.Service{
availableps = append(availableps, model.OOAPIService{
Address: config.ProbeServicesURL,
Type: "https",
})
@@ -347,8 +347,8 @@ func (ckw *CheckInConfigWebConnectivity) Add(cat string) {
ckw.CategoryCodes = append(ckw.CategoryCodes, cat)
}
func (ckw *CheckInConfigWebConnectivity) toModel() model.CheckInConfigWebConnectivity {
return model.CheckInConfigWebConnectivity{
func (ckw *CheckInConfigWebConnectivity) toModel() model.OOAPICheckInConfigWebConnectivity {
return model.OOAPICheckInConfigWebConnectivity{
CategoryCodes: ckw.CategoryCodes,
}
}
@@ -386,7 +386,7 @@ type CheckInInfoWebConnectivity struct {
ReportID string
// URLs contains the list of URLs to measure.
URLs []model.URLInfo
URLs []model.OOAPIURLInfo
}
// URLInfo contains info on a specific URL to measure.
@@ -421,7 +421,7 @@ func (ckw *CheckInInfoWebConnectivity) At(idx int64) *URLInfo {
}
}
func newCheckInInfoWebConnectivity(ckw *model.CheckInInfoWebConnectivity) *CheckInInfoWebConnectivity {
func newCheckInInfoWebConnectivity(ckw *model.OOAPICheckInInfoWebConnectivity) *CheckInInfoWebConnectivity {
if ckw == nil {
return nil
}
@@ -466,7 +466,7 @@ func (sess *Session) CheckIn(ctx *Context, config *CheckInConfig) (*CheckInInfo,
if sess.TestingCheckInBeforeCheckIn != nil {
sess.TestingCheckInBeforeCheckIn(ctx) // for testing
}
cfg := model.CheckInConfig{
cfg := model.OOAPICheckInConfig{
Charging: config.Charging,
OnWiFi: config.OnWiFi,
Platform: config.Platform,
@@ -494,7 +494,7 @@ type URLListConfig struct {
// URLListResult contains the URLs returned from the FetchURL API
type URLListResult struct {
Results []model.URLInfo
Results []model.OOAPIURLInfo
}
// AddCategory adds category code to the array in URLListConfig
@@ -538,7 +538,7 @@ func (sess *Session) FetchURLList(ctx *Context, config *URLListConfig) (*URLList
config.CountryCode = info.CountryCode
}
}
cfg := model.URLListConfig{
cfg := model.OOAPIURLListConfig{
Categories: config.Categories,
CountryCode: config.CountryCode,
Limit: config.Limit,
+1 -1
View File
@@ -13,7 +13,7 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/geolocate"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/pkg/oonimkall"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package oonimkall
import (
"fmt"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type loggerVerbose struct {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type RecordingLogger struct {
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"errors"
"testing"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type eventlike struct {
+1 -1
View File
@@ -3,7 +3,7 @@ package oonimkall
import (
"fmt"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
//
+1 -1
View File
@@ -3,7 +3,7 @@ package oonimkall
import (
"testing"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
//
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"sync"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
//
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"io"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
//
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@@ -68,7 +68,7 @@ func (r *runnerForTask) newsession(ctx context.Context, logger model.Logger) (ta
TunnelDir: r.settings.TunnelDir,
}
if r.settings.Options.ProbeServicesBaseURL != "" {
config.AvailableProbeServices = []model.Service{{
config.AvailableProbeServices = []model.OOAPIService{{
Type: "https",
Address: r.settings.Options.ProbeServicesBaseURL,
}}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/google/go-cmp/cmp"
engine "github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
func TestMeasurementSubmissionEventName(t *testing.T) {
+1 -1
View File
@@ -4,8 +4,8 @@ import (
"context"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/model"
)
//
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
func TestWebConnectivityRunnerWithMaybeLookupBackendsFailure(t *testing.T) {