fix(dnscheck): log "ok" rather than "<nil>" on success (#695)
See https://github.com/ooni/probe/issues/2020
This commit is contained in:
parent
88236a4352
commit
6a63f1b044
|
@ -68,6 +68,9 @@ run `go mod tidy` to minimize such changes.
|
||||||
- use `./internal/netxlite.ReadAllContext` instead of `io.ReadAll`
|
- use `./internal/netxlite.ReadAllContext` instead of `io.ReadAll`
|
||||||
and `./internal/netxlite.CopyContext` instead of `io.Copy`
|
and `./internal/netxlite.CopyContext` instead of `io.Copy`
|
||||||
|
|
||||||
|
- use `./internal/model.ErrorToStringOrOK` when
|
||||||
|
an experiment logs intermediate results
|
||||||
|
|
||||||
## Code testing requirements
|
## Code testing requirements
|
||||||
|
|
||||||
Make sure all tests pass with `go test -race ./...` run from the
|
Make sure all tests pass with `go test -race ./...` run from the
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 757 KiB After Width: | Height: | Size: 722 KiB |
|
@ -272,7 +272,7 @@ func Collect(ctx context.Context, multi urlgetter.Multi, inputs []urlgetter.Mult
|
||||||
count++
|
count++
|
||||||
percentage := float64(count) / float64(expect)
|
percentage := float64(count) / float64(expect)
|
||||||
callbacks.OnProgress(percentage, fmt.Sprintf(
|
callbacks.OnProgress(percentage, fmt.Sprintf(
|
||||||
"dnscheck: measure %s: %+v", entry.Input.Config.ResolverURL, entry.Err,
|
"dnscheck: measure %s: %+v", entry.Input.Config.ResolverURL, model.ErrorToStringOrOK(entry.Err),
|
||||||
))
|
))
|
||||||
outputch <- entry
|
outputch <- entry
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,3 +61,11 @@ func (logDiscarder) Warn(msg string) {}
|
||||||
|
|
||||||
// Warnf implements Logger.Warnf
|
// Warnf implements Logger.Warnf
|
||||||
func (logDiscarder) Warnf(format string, v ...interface{}) {}
|
func (logDiscarder) Warnf(format string, v ...interface{}) {}
|
||||||
|
|
||||||
|
// ErrorToStringOrOK emits "ok" on "<nil>"" values for success.
|
||||||
|
func ErrorToStringOrOK(err error) string {
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
return "ok"
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"io"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestDiscardLoggerWorksAsIntended(t *testing.T) {
|
func TestDiscardLoggerWorksAsIntended(t *testing.T) {
|
||||||
logger := DiscardLogger
|
logger := DiscardLogger
|
||||||
|
@ -11,3 +14,20 @@ func TestDiscardLoggerWorksAsIntended(t *testing.T) {
|
||||||
logger.Warn("foo")
|
logger.Warn("foo")
|
||||||
logger.Warnf("%s", "foo")
|
logger.Warnf("%s", "foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestErrorToStringOrOK(t *testing.T) {
|
||||||
|
t.Run("on success", func(t *testing.T) {
|
||||||
|
expectedResult := ErrorToStringOrOK(nil)
|
||||||
|
if expectedResult != "ok" {
|
||||||
|
t.Fatal("expected ok")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("on failure", func(t *testing.T) {
|
||||||
|
err := io.EOF
|
||||||
|
expectedResult := ErrorToStringOrOK(err)
|
||||||
|
if expectedResult != err.Error() {
|
||||||
|
t.Fatal("not the result we expected", expectedResult)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user