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 := NewDefaultCollectionFileStore() 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)) }