76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package db
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"git.andreafazzi.eu/andrea/probo/client"
|
|
"git.andreafazzi.eu/andrea/probo/hasher/sha256"
|
|
"git.andreafazzi.eu/andrea/probo/store/memory"
|
|
"github.com/remogatto/prettytest"
|
|
)
|
|
|
|
type dbTestSuite struct {
|
|
prettytest.Suite
|
|
}
|
|
|
|
func TestRunner(t *testing.T) {
|
|
prettytest.Run(
|
|
t,
|
|
new(dbTestSuite),
|
|
)
|
|
}
|
|
|
|
func (t *dbTestSuite) TestCreateExam() {
|
|
memStore := memory.NewMemoryProboCollectorStore(
|
|
sha256.NewDefault256Hasher(sha256.DefaultSHA256HashingFn),
|
|
)
|
|
memStore.CreateQuiz(
|
|
&client.CreateUpdateQuizRequest{
|
|
Quiz: &client.Quiz{
|
|
Question: &client.Question{Text: "Newly created 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},
|
|
},
|
|
},
|
|
})
|
|
|
|
store, err := NewDBProboCollectorStore("testdata/test.sqlite", memStore)
|
|
defer os.Remove("testdata/test.sqlite")
|
|
|
|
t.Nil(err)
|
|
|
|
if !t.Failed() {
|
|
collection, err := memStore.CreateCollection(&client.CreateUpdateCollectionRequest{
|
|
Collection: &client.Collection{
|
|
Name: "Collection name",
|
|
Query: "#tag1",
|
|
},
|
|
})
|
|
|
|
t.Nil(err)
|
|
|
|
if !t.Failed() {
|
|
exam, err := store.CreateExam(&client.CreateUpdateExamRequest{
|
|
Exam: &client.Exam{
|
|
Name: "Exam",
|
|
Description: "Exam description",
|
|
CollectionID: collection.ID,
|
|
},
|
|
})
|
|
|
|
t.Nil(err)
|
|
if !t.Failed() {
|
|
t.Not(t.Nil(exam))
|
|
examFromDb, err := store.ReadExamByID(&client.ReadExamByIDRequest{ID: exam.ID})
|
|
t.Nil(err)
|
|
if !t.Failed() {
|
|
t.Equal(examFromDb.ID, exam.ID)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|