feat(miniooni): optionally log using emojis (#932)

As silly as it seems, emojis help _a lot_ when eyeballing logs
to quickly identify unexpected lines.

I'm doing this work as part of https://github.com/ooni/probe/issues/2257
This commit is contained in:
Simone Basso 2022-09-05 10:06:44 +02:00 committed by GitHub
commit 34dc029b33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 225 additions and 36 deletions

View file

@ -0,0 +1,16 @@
package mocks
import "io"
// Writer allows to mock any io.Writer.
type Writer struct {
MockWrite func(b []byte) (int, error)
}
// Writer implements an io.Writer.
var _ io.Writer = &Writer{}
// Write implements io.Writer.Write.
func (r *Writer) Write(b []byte) (int, error) {
return r.MockWrite(b)
}

View file

@ -0,0 +1,25 @@
package mocks
import (
"errors"
"testing"
)
func TestWriter(t *testing.T) {
t.Run("Write", func(t *testing.T) {
expected := errors.New("mocked error")
r := &Writer{
MockWrite: func(b []byte) (int, error) {
return 0, expected
},
}
b := make([]byte, 128)
count, err := r.Write(b)
if !errors.Is(err, expected) {
t.Fatal("unexpected error", err)
}
if count != 0 {
t.Fatal("unexpected count", count)
}
})
}