Files
BanForge/internal/storage/writer_test.go
d3m0k1d 341f49c4b4
Some checks failed
build / build (push) Failing after 2m48s
feat: improve db logic and logger(untested)
2026-01-21 20:44:28 +03:00

41 lines
590 B
Go

package storage
import (
"testing"
"time"
)
func TestWrite(t *testing.T) {
var ip string
d := createTestDBStruct(t)
err := d.CreateTable()
if err != nil {
t.Fatal(err)
}
resultCh := make(chan *LogEntry)
go Write(d, resultCh)
resultCh <- &LogEntry{
Service: "test",
IP: "127.0.0.1",
Path: "/test",
Method: "GET",
Status: "200",
}
close(resultCh)
time.Sleep(200 * time.Millisecond)
err = d.db.QueryRow("SELECT ip FROM requests LIMIT 1").Scan(&ip)
if err != nil {
t.Fatal(err)
}
if ip != "127.0.0.1" {
t.Fatal("ip should be 127.0.0.1")
}
}