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
+4 -19
View File
@@ -8,17 +8,11 @@ import (
"github.com/armon/go-socks5"
"github.com/cretz/bine/control"
"github.com/cretz/bine/tor"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/psiphon/oopsi/github.com/Psiphon-Labs/psiphon-tunnel-core/ClientLibrary/clientlib"
"golang.org/x/sys/execabs"
)
// Logger is the logger to use. Its signature is compatibile
// with the apex/log logger signature.
type Logger interface {
// Infof formats and emits an informative message
Infof(format string, v ...interface{})
}
// Config contains the configuration for creating a Tunnel instance. You need
// to fill all the mandatory fields. You SHOULD NOT modify the content of this
// structure while in use, because that may lead to data races.
@@ -41,7 +35,7 @@ type Config struct {
// Logger is the optional logger to use. If empty we use a default
// implementation that does not emit any output.
Logger Logger
Logger model.InfoLogger
// TorArgs contains the optional arguments that you want us to pass
// to the tor binary when invoking it. By default we do not
@@ -81,21 +75,12 @@ type Config struct {
testTorGetInfo func(ctrl *control.Conn, keys ...string) ([]*control.KeyVal, error)
}
// silentLogger is a logger that does not emit output.
type silentLogger struct{}
// Infof implements Logger.Infof.
func (sl *silentLogger) Infof(format string, v ...interface{}) {}
// defaultLogger is the default logger.
var defaultLogger = &silentLogger{}
// logger returns the logger to use.
func (c *Config) logger() Logger {
func (c *Config) logger() model.InfoLogger {
if c.Logger != nil {
return c.Logger
}
return defaultLogger
return model.DiscardLogger
}
// execabsLookPath calls either testExeabsLookPath or execabs.LookPath
+2 -1
View File
@@ -6,11 +6,12 @@ import (
"testing"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/model"
)
func TestConfigLoggerDefault(t *testing.T) {
config := &Config{}
if config.logger() != defaultLogger {
if config.logger() != model.DiscardLogger {
t.Fatal("not the logger we expected")
}
}