package file import ( "fmt" "os" "git.andreafazzi.eu/andrea/probo/client" "github.com/remogatto/prettytest" ) type collectionTestSuite struct { prettytest.Suite } func (t *collectionTestSuite) TestCreateCollection() { store, err := NewFileProboCollectorStore(testdataDir) t.Nil(err, fmt.Sprintf("A file store should be initialized without problems but an error occurred: %v", err)) if !t.Failed() { quiz_1, err := createQuizOnDisk(store, &client.CreateUpdateQuizRequest{ Quiz: &client.Quiz{ Question: &client.Question{Text: "Question text with #tag1."}, Answers: []*client.Answer{ {Text: "Answer 1", Correct: true}, {Text: "Answer 2", Correct: false}, {Text: "Answer 3", Correct: false}, {Text: "Answer 4", Correct: false}, }, }, }) t.Nil(err, "The quiz to be updated should be created without issue") path_1, _ := store.GetQuizPath(quiz_1) if !t.Failed() { quiz_2, err := createQuizOnDisk(store, &client.CreateUpdateQuizRequest{ Quiz: &client.Quiz{ Question: &client.Question{Text: "Another question text with #tag1."}, Answers: []*client.Answer{ {Text: "Answer 1", Correct: true}, {Text: "Answer 2", Correct: false}, {Text: "Answer 3", Correct: false}, {Text: "Answer 4", Correct: false}, }, }, }) t.Nil(err, "The quiz to be updated should be created without issue") path_2, _ := store.GetQuizPath(quiz_2) if !t.Failed() { quiz_3, err := createQuizOnDisk(store, &client.CreateUpdateQuizRequest{ Quiz: &client.Quiz{ Question: &client.Question{Text: "Question text without tags."}, Answers: []*client.Answer{ {Text: "Answer 1", Correct: true}, {Text: "Answer 2", Correct: false}, {Text: "Answer 3", Correct: false}, {Text: "Answer 4", Correct: false}, }, }, }) t.Nil(err, "The quiz to be updated should be created without issue") path_3, _ := store.GetQuizPath(quiz_3) if !t.Failed() { collection, err := store.CreateCollection( &client.CreateUpdateCollectionRequest{ Collection: &client.Collection{ Name: "MyCollection", Query: "#tag1", }, }) t.Nil(err, "Creating a collection should not return an error") collectionPath, _ := store.GetCollectionPath(collection) if !t.Failed() { t.Equal(2, len(collection.IDs)) os.Remove(path_1) os.Remove(path_2) os.Remove(path_3) os.Remove(collectionPath) } } } } } }