mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-09-26 21:01:14 +08:00
25
test/log.go
25
test/log.go
@@ -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
|
||||
|
@@ -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))
|
||||
|
Reference in New Issue
Block a user