36 lines
690 B
Go
36 lines
690 B
Go
package logfile
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestDatabaseWrite(t *testing.T) {
|
|
cases := []string{"280312038j1203j8120938j120938120938d12903h1207h13926410327h46012346073",
|
|
"google.com",
|
|
"localhost",
|
|
"some.weird.absodas"}
|
|
|
|
var sb = new(ShapeDb)
|
|
err := sb.Open("dict.db")
|
|
if err != nil {
|
|
t.Fatal("failed to open db")
|
|
}
|
|
hshs := make([][4]byte, len(cases))
|
|
for i, c := range cases {
|
|
hshs[i], err = sb.Add([]byte(c))
|
|
if err != nil {
|
|
t.Fatalf("failed to add %s %v", c, err)
|
|
}
|
|
}
|
|
|
|
for i, v := range hshs {
|
|
val, err := sb.Get(v)
|
|
if err != nil {
|
|
t.Fatalf("failed to get %s %v", val, err)
|
|
}
|
|
if string(val) != cases[i] {
|
|
t.Fatalf("val no match %s", val)
|
|
}
|
|
}
|
|
}
|