import other kontor repos into directories

This commit is contained in:
Thomas Peetz
2025-01-09 19:28:50 +01:00
committed by Thomas Peetz
parent 28746adfbb
commit b424e95e05
319 changed files with 17211 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
package library
import (
"gitlab.thpeetz.de/kontor/kontor-go/pkg/dao"
"reflect"
"testing"
"gopkg.in/mgo.v2/bson"
)
var authorModelTestTable = []struct {
name string
typeName string
}{
{"Id", "string"},
{"Name", "string"},
{"Model", "string"},
}
func TestAuthorModel(t *testing.T) {
m := Author{}
if reflect.TypeOf(m).NumField() != len(authorModelTestTable) {
t.Fail()
}
for index, testData := range authorModelTestTable {
givenType := reflect.TypeOf(m).Field(index).Type.Kind().String()
if givenType != testData.typeName {
t.Fail()
}
}
}
func TestListAuthors(t *testing.T) {
var (
authorDao = AuthorDAO{Db: dao.TestDb}
)
authors, err := authorDao.FindAll()
if err != nil {
t.Fail()
}
if len(authors) != 0 {
t.Fail()
}
}
func TestInsertAuthor(t *testing.T) {
var (
authorDao = AuthorDAO{Db: dao.TestDb}
author = Author{}
authors []Author
)
author.ID = bson.NewObjectId()
author.Name = "Packt Publishing"
err := authorDao.Insert(author)
if err != nil {
t.Fail()
}
authors, err = authorDao.FindAll()
if len(authors) != 1 {
t.Fail()
}
}
func TestUpsertAuthor(t *testing.T) {
var (
authorDao = AuthorDAO{Db: dao.TestDb}
)
var author = Author{}
author.ID = bson.NewObjectId()
author.Name = "Hansa Verlag"
authorDao.Upsert(author)
authors, err := authorDao.FindAll()
if err != nil {
t.Fail()
}
if len(authors) != 2 {
t.Fail()
}
}
func TestDeleteAuthor(t *testing.T) {
var (
authorDao = AuthorDAO{Db: dao.TestDb}
)
authors, err := authorDao.FindAll()
if err != nil {
t.Fail()
}
for _, author := range authors {
authorDao.Delete(author)
}
authors, err = authorDao.FindAll()
if err != nil {
t.Fail()
}
if len(authors) != 0 {
t.Fail()
}
}