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:
@@ -1,39 +1,21 @@
|
||||
package scrubber
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
// UnderlyingLogger defines the common interface that a logger should have. It is
|
||||
// out of the box compatible with `log.Log` in `apex/log`.
|
||||
type UnderlyingLogger interface {
|
||||
// Debug emits a debug message.
|
||||
Debug(msg string)
|
||||
|
||||
// Debugf formats and emits a debug message.
|
||||
Debugf(format string, v ...interface{})
|
||||
|
||||
// Info emits an informational message.
|
||||
Info(msg string)
|
||||
|
||||
// Infof formats and emits an informational message.
|
||||
Infof(format string, v ...interface{})
|
||||
|
||||
// Warn emits a warning message.
|
||||
Warn(msg string)
|
||||
|
||||
// Warnf formats and emits a warning message.
|
||||
Warnf(format string, v ...interface{})
|
||||
}
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// Logger is a Logger with scrubbing. All messages are scrubbed
|
||||
// including the ones that won't be emitted. As such, this logger
|
||||
// is less efficient than a logger without scrubbing.
|
||||
type Logger struct {
|
||||
UnderlyingLogger
|
||||
model.Logger
|
||||
}
|
||||
|
||||
// Debug scrubs and emits a debug message.
|
||||
func (sl *Logger) Debug(message string) {
|
||||
sl.UnderlyingLogger.Debug(Scrub(message))
|
||||
sl.Logger.Debug(Scrub(message))
|
||||
}
|
||||
|
||||
// Debugf scrubs, formats, and emits a debug message.
|
||||
@@ -43,7 +25,7 @@ func (sl *Logger) Debugf(format string, v ...interface{}) {
|
||||
|
||||
// Info scrubs and emits an informational message.
|
||||
func (sl *Logger) Info(message string) {
|
||||
sl.UnderlyingLogger.Info(Scrub(message))
|
||||
sl.Logger.Info(Scrub(message))
|
||||
}
|
||||
|
||||
// Infof scrubs, formats, and emits an informational message.
|
||||
@@ -53,7 +35,7 @@ func (sl *Logger) Infof(format string, v ...interface{}) {
|
||||
|
||||
// Warn scrubs and emits a warning message.
|
||||
func (sl *Logger) Warn(message string) {
|
||||
sl.UnderlyingLogger.Warn(Scrub(message))
|
||||
sl.Logger.Warn(Scrub(message))
|
||||
}
|
||||
|
||||
// Warnf scrubs, formats, and emits a warning message.
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestScrubLogger(t *testing.T) {
|
||||
|
||||
t.Run("for debug", func(t *testing.T) {
|
||||
logger := new(savingLogger)
|
||||
scrubber := &Logger{UnderlyingLogger: logger}
|
||||
scrubber := &Logger{Logger: logger}
|
||||
scrubber.Debug(input)
|
||||
if len(logger.debug) != 1 && len(logger.info) != 0 && len(logger.warn) != 0 {
|
||||
t.Fatal("unexpected number of log lines written")
|
||||
@@ -53,7 +53,7 @@ func TestScrubLogger(t *testing.T) {
|
||||
|
||||
t.Run("for debugf", func(t *testing.T) {
|
||||
logger := new(savingLogger)
|
||||
scrubber := &Logger{UnderlyingLogger: logger}
|
||||
scrubber := &Logger{Logger: logger}
|
||||
scrubber.Debugf("%s", input)
|
||||
if len(logger.debug) != 1 && len(logger.info) != 0 && len(logger.warn) != 0 {
|
||||
t.Fatal("unexpected number of log lines written")
|
||||
@@ -65,7 +65,7 @@ func TestScrubLogger(t *testing.T) {
|
||||
|
||||
t.Run("for info", func(t *testing.T) {
|
||||
logger := new(savingLogger)
|
||||
scrubber := &Logger{UnderlyingLogger: logger}
|
||||
scrubber := &Logger{Logger: logger}
|
||||
scrubber.Info(input)
|
||||
if len(logger.debug) != 0 && len(logger.info) != 1 && len(logger.warn) != 0 {
|
||||
t.Fatal("unexpected number of log lines written")
|
||||
@@ -77,7 +77,7 @@ func TestScrubLogger(t *testing.T) {
|
||||
|
||||
t.Run("for infof", func(t *testing.T) {
|
||||
logger := new(savingLogger)
|
||||
scrubber := &Logger{UnderlyingLogger: logger}
|
||||
scrubber := &Logger{Logger: logger}
|
||||
scrubber.Infof("%s", input)
|
||||
if len(logger.debug) != 0 && len(logger.info) != 1 && len(logger.warn) != 0 {
|
||||
t.Fatal("unexpected number of log lines written")
|
||||
@@ -89,7 +89,7 @@ func TestScrubLogger(t *testing.T) {
|
||||
|
||||
t.Run("for warn", func(t *testing.T) {
|
||||
logger := new(savingLogger)
|
||||
scrubber := &Logger{UnderlyingLogger: logger}
|
||||
scrubber := &Logger{Logger: logger}
|
||||
scrubber.Warn(input)
|
||||
if len(logger.debug) != 0 && len(logger.info) != 0 && len(logger.warn) != 1 {
|
||||
t.Fatal("unexpected number of log lines written")
|
||||
@@ -101,7 +101,7 @@ func TestScrubLogger(t *testing.T) {
|
||||
|
||||
t.Run("for warnf", func(t *testing.T) {
|
||||
logger := new(savingLogger)
|
||||
scrubber := &Logger{UnderlyingLogger: logger}
|
||||
scrubber := &Logger{Logger: logger}
|
||||
scrubber.Warnf("%s", input)
|
||||
if len(logger.debug) != 0 && len(logger.info) != 0 && len(logger.warn) != 1 {
|
||||
t.Fatal("unexpected number of log lines written")
|
||||
|
||||
Reference in New Issue
Block a user