replace main to test modul

This commit is contained in:
Adrian Zürcher
2025-12-12 10:00:39 +01:00
parent c31761dc10
commit a022a9a8ba
2 changed files with 42 additions and 20 deletions

42
logger_test.go Normal file
View File

@@ -0,0 +1,42 @@
package tecaminologger
import (
"errors"
"os"
"testing"
"gitea.tecamino.com/paadi/tecamino-logger/logging"
)
func TestLogger(t *testing.T) {
t.Log("start logger test")
logFile := "Test.log"
log, err := logging.NewLogger(logFile, nil)
if err != nil {
t.Fatal(err)
}
log.Info("line 10", "hallo")
log.Warning("line 11", "vello")
log.Error("line 12", "hie")
err = errors.New("test error")
log.Error("line 14", err)
log.Debug("line 15", "isch")
t.Log("read created log file")
f, err := os.ReadFile(logFile)
if err != nil {
t.Fatal(err)
}
t.Log("read created log file")
t.Log(string(f))
t.Log("test if log file name empty")
log, err = logging.NewLogger("", nil)
if err != nil {
t.Fatal(err)
}
log.Info("test", "this is a text")
}