netxlite: improve docs, tests, and code quality (#493)
* netxlite: improve docs, tests, and code quality * better documentation * more strict testing of dialer (especially make sure we document the quirk in https://github.com/ooni/probe/issues/1779 and we have tests to guarantee we don't screw up here) * introduce NewErrWrapper factory for creating errors so we have confidence we are creating them correctly Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package mocks
|
||||
|
||||
// Logger allows mocking a logger.
|
||||
type Logger struct {
|
||||
MockDebug func(message string)
|
||||
|
||||
MockDebugf func(format string, v ...interface{})
|
||||
}
|
||||
|
||||
// Debug calls MockDebug.
|
||||
func (lo *Logger) Debug(message string) {
|
||||
lo.MockDebug(message)
|
||||
}
|
||||
|
||||
// Debugf calls MockDebugf.
|
||||
func (lo *Logger) Debugf(format string, v ...interface{}) {
|
||||
lo.MockDebugf(format, v...)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package mocks
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestLogger(t *testing.T) {
|
||||
t.Run("Debug", func(t *testing.T) {
|
||||
var called bool
|
||||
lo := &Logger{
|
||||
MockDebug: func(message string) {
|
||||
called = true
|
||||
},
|
||||
}
|
||||
lo.Debug("antani")
|
||||
if !called {
|
||||
t.Fatal("not called")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Debugf", func(t *testing.T) {
|
||||
var called bool
|
||||
lo := &Logger{
|
||||
MockDebugf: func(message string, v ...interface{}) {
|
||||
called = true
|
||||
},
|
||||
}
|
||||
lo.Debugf("antani", 1, 2, 3, 4)
|
||||
if !called {
|
||||
t.Fatal("not called")
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user