dndex/storage/driver/storage_test.go

49 lines
1.1 KiB
Go

package driver
import (
"encoding/json"
"local/dndex/storage/entity"
"testing"
"time"
"github.com/google/uuid"
)
func TestNewStorage(t *testing.T) {
tempStorage(t)
}
func tempStorage(t *testing.T) *Storage {
s := NewStorage()
fillStorage(t, s)
return s
}
func fillStorage(t *testing.T, s *Storage) {
for i := 0; i < testN; i++ {
p := entity.One{
ID: "iddd-" + uuid.New().String()[:5],
Name: "name-" + uuid.New().String()[:5],
Type: "type-" + uuid.New().String()[:5],
Title: "titl-" + uuid.New().String()[:5],
}
o := entity.One{
ID: "iddd-" + uuid.New().String()[:5],
Name: "name-" + uuid.New().String()[:5],
Type: "type-" + uuid.New().String()[:5],
Title: "titl-" + uuid.New().String()[:5],
Text: "text-" + uuid.New().String()[:5],
Modified: time.Now().UnixNano(),
Connections: map[string]entity.Connection{p.ID: entity.Connection{p.Name}},
Attachments: map[string]entity.Attachment{"filename": {"/path/to/file"}},
}
b, err := json.Marshal(o)
if err != nil {
t.Fatal(err)
}
if err := s.db.Set(o.ID, b, testNS); err != nil {
t.Fatal(err)
}
}
}