-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggdb_test.go
45 lines (36 loc) · 1.07 KB
/
loggdb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package loggdb_test
import (
"bytes"
"testing"
"github.com/m1ndo/LogGdb"
)
func TestLogger(t *testing.T) {
// Create a temporary directory for the log file
// Create a logger instance
logger := &loggdb.Logger{
LogDir: "logs",
}
err := logger.NewLogger()
if err != nil {
panic(err)
}
// Set up a buffer to capture the log output
var buf bytes.Buffer
logger.SetOutput(&buf)
// Write some log messages
logger.Info("This is an info message")
logger.Error("This is an error message")
// Get the captured log output from the buffer
logOutput := buf.String()
// Check if the log output contains the expected messages
if !contains(logOutput, "This is an info message") {
t.Errorf("Expected log output to contain 'This is an info message', got: %s", logOutput)
}
if !contains(logOutput, "This is an error message") {
t.Errorf("Expected log output to contain 'This is an error message', got: %s", logOutput)
}
}
// Helper function to check if a string contains a substring
func contains(str, substr string) bool {
return bytes.Contains([]byte(str), []byte(substr))
}