Coverage: Fprint testing

This commit is contained in:
kayos@tcp.direct 2022-05-29 22:29:07 -07:00
parent 56c9b804e5
commit 0dda286965
Signed by: kayos
GPG Key ID: 4B841471B4BEE979

View File

@ -1,9 +1,11 @@
package common
import (
"errors"
"fmt"
"io"
"os"
"sync"
"testing"
"git.tcp.direct/kayos/common/entropy"
@ -85,3 +87,33 @@ func TestCruisinInMy64(t *testing.T) {
}
t.Logf("original float64: %v -> Float64ToBytes %v -> BytesToFloat64 %v", data, databytes, result)
}
type phonyWriter struct{}
var o = &sync.Once{}
var fprintStatus bool
var pw = new(phonyWriter)
func (p2 phonyWriter) Write(p []byte) (int, error) {
var err = errors.New("closed")
fprintStatus = false
o.Do(func() {
err = nil
fprintStatus = true
})
if err == nil {
return len(p), err
}
return 0, err
}
func TestFprint(t *testing.T) {
Fprint(pw, "asdf")
if fprintStatus != true {
t.Fatal("first Fprint test should have succeeded")
}
Fprint(pw, "asdf")
if fprintStatus != false {
t.Fatal("second Fprint test should not have succeeded")
}
}