yanic/database/logging/file_test.go

61 lines
1.3 KiB
Go
Raw Permalink Normal View History

package logging
import (
"os"
"testing"
"time"
"github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/runtime"
"github.com/stretchr/testify/assert"
)
func TestStart(t *testing.T) {
assert := assert.New(t)
conn, err := Connect(map[string]interface{}{
"path": "/dev/notexists/file",
})
assert.Nil(conn)
assert.Error(err)
path := "/tmp/testlogfile"
conn, err = Connect(map[string]interface{}{
"path": path,
})
2018-01-13 16:49:37 +01:00
assert.NoError(err)
2023-09-18 10:55:05 +02:00
dat, _ := os.ReadFile(path)
assert.NotContains(string(dat), "InsertNode")
conn.InsertNode(&runtime.Node{
Statistics: &data.Statistics{},
})
2023-09-18 10:55:05 +02:00
dat, _ = os.ReadFile(path)
assert.Contains(string(dat), "InsertNode")
assert.NotContains(string(dat), "InsertLink")
conn.InsertLink(&runtime.Link{}, time.Now())
2023-09-18 10:55:05 +02:00
dat, _ = os.ReadFile(path)
assert.Contains(string(dat), "InsertLink")
assert.NotContains(string(dat), "InsertGlobals")
conn.InsertGlobals(&runtime.GlobalStats{}, time.Now(), runtime.GLOBAL_SITE, runtime.GLOBAL_DOMAIN)
2023-09-18 10:55:05 +02:00
dat, _ = os.ReadFile(path)
assert.Contains(string(dat), "InsertGlobals")
assert.NotContains(string(dat), "PruneNodes")
conn.PruneNodes(time.Second)
2023-09-18 10:55:05 +02:00
dat, _ = os.ReadFile(path)
assert.Contains(string(dat), "PruneNodes")
assert.NotContains(string(dat), "Close")
conn.Close()
2023-09-18 10:55:05 +02:00
dat, _ = os.ReadFile(path)
assert.Contains(string(dat), "Close")
os.Remove(path)
}