feat: transaction implement
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoggerWritesConsoleAndFile(t *testing.T) {
|
||||
t.Parallel()
|
||||
var console bytes.Buffer
|
||||
path := filepath.Join(t.TempDir(), "daemon.log")
|
||||
logger, closer, err := NewWithConsole(&console, path)
|
||||
if err != nil {
|
||||
t.Fatalf("create logger: %v", err)
|
||||
}
|
||||
logger.Info("transaction created", "transaction_id", "transaction-1")
|
||||
if err := closer.Close(); err != nil {
|
||||
t.Fatalf("close logger: %v", err)
|
||||
}
|
||||
fileContent, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read log file: %v", err)
|
||||
}
|
||||
for name, content := range map[string]string{
|
||||
"console": console.String(),
|
||||
"file": string(fileContent),
|
||||
} {
|
||||
if !strings.Contains(content, "transaction created") || !strings.Contains(content, "transaction_id=transaction-1") {
|
||||
t.Fatalf("%s log is missing fields: %q", name, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user