79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
package file
|
|
|
|
import (
|
|
"os"
|
|
|
|
"git.andreafazzi.eu/andrea/probo/models"
|
|
"git.andreafazzi.eu/andrea/probo/store"
|
|
"github.com/remogatto/prettytest"
|
|
)
|
|
|
|
type collectionTestSuite struct {
|
|
prettytest.Suite
|
|
}
|
|
|
|
func (t *collectionTestSuite) TestCreateCollection() {
|
|
quizStore := store.NewQuizStore()
|
|
|
|
quizStore.Create(
|
|
&models.Quiz{
|
|
Question: &models.Question{Text: "Question text #tag1 #tag3."},
|
|
Answers: []*models.Answer{
|
|
{Text: "Answer 1"},
|
|
{Text: "Answer 2"},
|
|
{Text: "Answer 3"},
|
|
{Text: "Answer 4"},
|
|
},
|
|
})
|
|
|
|
quizStore.Create(
|
|
&models.Quiz{
|
|
Question: &models.Question{Text: "Question text #tag2."},
|
|
Answers: []*models.Answer{
|
|
{Text: "Answer 1"},
|
|
{Text: "Answer 2"},
|
|
{Text: "Answer 3"},
|
|
{Text: "Answer 4"},
|
|
},
|
|
})
|
|
|
|
quizStore.Create(
|
|
&models.Quiz{
|
|
Question: &models.Question{Text: "Question text #tag3."},
|
|
Answers: []*models.Answer{
|
|
{Text: "Answer 1"},
|
|
{Text: "Answer 2"},
|
|
{Text: "Answer 3"},
|
|
{Text: "Answer 4"},
|
|
},
|
|
})
|
|
|
|
store, err := NewCollectionFileStore(
|
|
&FileStoreConfig[*models.Collection, *store.CollectionStore]{
|
|
FilePathConfig: FilePathConfig{"testdata", "collection", ".json"},
|
|
IndexDirFunc: DefaultIndexDirFunc[*models.Collection, *store.CollectionStore],
|
|
UnmarshalFunc: DefaultUnmarshalCollectionFunc,
|
|
MarshalFunc: DefaultMarshalCollectionFunc,
|
|
},
|
|
)
|
|
t.Nil(err)
|
|
|
|
c := new(models.Collection)
|
|
c.Name = "MyCollection"
|
|
|
|
quizStore.FilterInCollection(c, &models.Filter{
|
|
Tags: []*models.Tag{
|
|
{Name: "#tag3"},
|
|
},
|
|
})
|
|
|
|
_, err = store.Create(c)
|
|
|
|
exists, err := os.Stat(store.GetPath(c))
|
|
|
|
t.Nil(err)
|
|
t.Not(t.Nil(exists))
|
|
t.Equal(2, len(c.Quizzes))
|
|
|
|
defer os.Remove(store.GetPath(c))
|
|
}
|