initial commit
This commit is contained in:
commit
c21f569144
37 changed files with 3956 additions and 0 deletions
82
database/database_test.go
Normal file
82
database/database_test.go
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"foobar/model"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
_ = New()
|
||||
}
|
||||
|
||||
func TestGetBox(t *testing.T) {
|
||||
_ = New()
|
||||
|
||||
boxURL, err := model.CheckBoxURL("1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b, err := SelectBox(boxURL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if b.ID().String() == "" {
|
||||
t.Fatalf("")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInsertBox(t *testing.T) {
|
||||
|
||||
_ = New()
|
||||
tx := MustBeginTx()
|
||||
defer tx.Rollback()
|
||||
|
||||
url, err := model.CheckBoxURL("foobar")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
box := model.NewBox(uuid.New(), url, "foobar", "", false, false, time.Now(), time.Now())
|
||||
|
||||
err = InsertBox(tx, box, "foobar", "foobar")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterFile(t *testing.T) {
|
||||
_ = New()
|
||||
tx := MustBeginTx()
|
||||
defer tx.Rollback()
|
||||
|
||||
url, err := model.CheckBoxURL("foobar")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
box := model.NewBox(uuid.New(), url, "foobar", "", false, false, time.Now(), time.Now())
|
||||
|
||||
err = InsertBox(tx, box, "foobar", "foobar")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var file = model.NewFile(
|
||||
uuid.New(), "foobar", 6, time.Now(), model.FileMime("plain/text"), md5.Sum([]byte("foobar")),
|
||||
)
|
||||
|
||||
err = InsertFile(tx, box.ID(), file)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue