Fix logging tests

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2023-06-21 08:56:09 +02:00
parent 8e4961e1f7
commit c8e5858314
28 changed files with 250 additions and 186 deletions

View File

@@ -6,30 +6,15 @@ package test
import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
"github.com/onsi/ginkgo/v2"
"go.uber.org/zap"
"github.com/stv0g/cunicu/pkg/log"
"github.com/stv0g/cunicu/pkg/tty"
)
type writerWrapper struct {
ginkgo.GinkgoWriterInterface
}
func (w *writerWrapper) Close() error {
return nil
}
func (w *writerWrapper) Sync() error {
return nil
}
func SetupLogging() *log.Logger {
logger, err := SetupLoggingWithFile("", false)
if err != nil {
@@ -40,15 +25,7 @@ func SetupLogging() *log.Logger {
}
func SetupLoggingWithFile(fn string, truncate bool) (*log.Logger, error) {
if err := zap.RegisterSink("ginkgo", func(u *url.URL) (zap.Sink, error) {
return &writerWrapper{
GinkgoWriterInterface: ginkgo.GinkgoWriter,
}, nil
}); err != nil && !strings.Contains(err.Error(), "already registered") {
panic(err)
}
outputPaths := []string{"ginkgo:"}
outputPaths := []string{"ginkgo"}
if fn != "" {
// Create parent directories for log file

View File

@@ -14,12 +14,11 @@ import (
)
func TestSuite(t *testing.T) {
test.SetupLogging()
RegisterFailHandler(Fail)
RunSpecs(t, "Test Helper Suite")
}
var _ = test.SetupLogging()
var _ = Describe("entropy", func() {
Specify("that the entropy of an empty slice is zero", func() {
Expect(test.Entropy([]byte{})).To(BeNumerically("==", 0))