79 lines
1.9 KiB
Go
79 lines
1.9 KiB
Go
|
package memory
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
|
||
|
"git.andreafazzi.eu/andrea/probo/client"
|
||
|
"git.andreafazzi.eu/andrea/probo/hasher/sha256"
|
||
|
"github.com/remogatto/prettytest"
|
||
|
)
|
||
|
|
||
|
type testSuite struct {
|
||
|
prettytest.Suite
|
||
|
}
|
||
|
|
||
|
func TestRunner(t *testing.T) {
|
||
|
prettytest.Run(
|
||
|
t,
|
||
|
new(testSuite),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
func (t *testSuite) TestReadQuizByHash() {
|
||
|
store := NewMemoryProboCollectorStore(
|
||
|
sha256.NewDefault256Hasher(sha256.DefaultSHA256HashingFn),
|
||
|
)
|
||
|
quiz, _ := store.CreateQuiz(
|
||
|
&client.CreateUpdateQuizRequest{
|
||
|
Quiz: &client.Quiz{
|
||
|
Question: &client.Question{Text: "Newly created question text."},
|
||
|
Answers: []*client.Answer{
|
||
|
{Text: "Answer 1", Correct: true},
|
||
|
{Text: "Answer 2", Correct: false},
|
||
|
{Text: "Answer 3", Correct: false},
|
||
|
{Text: "Answer 4", Correct: false},
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
quizFromMemory, err := store.ReadQuizByHash(quiz.Hash)
|
||
|
t.Nil(err, "Quiz should be found in the store")
|
||
|
if !t.Failed() {
|
||
|
t.True(reflect.DeepEqual(quizFromMemory, quiz), "Quiz should be equal")
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
func (t *testSuite) TestUpdateQuiz() {
|
||
|
store := NewMemoryProboCollectorStore(
|
||
|
sha256.NewDefault256Hasher(sha256.DefaultSHA256HashingFn),
|
||
|
)
|
||
|
quiz, _ := store.CreateQuiz(
|
||
|
&client.CreateUpdateQuizRequest{
|
||
|
Quiz: &client.Quiz{
|
||
|
Question: &client.Question{Text: "Newly created question text."},
|
||
|
Answers: []*client.Answer{
|
||
|
{Text: "Answer 1", Correct: true},
|
||
|
{Text: "Answer 2", Correct: false},
|
||
|
{Text: "Answer 3", Correct: false},
|
||
|
{Text: "Answer 4", Correct: false},
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
updatedQuiz, _ := store.CreateQuiz(
|
||
|
&client.CreateUpdateQuizRequest{
|
||
|
Quiz: &client.Quiz{
|
||
|
Question: &client.Question{Text: "Updated question text."},
|
||
|
Answers: []*client.Answer{
|
||
|
{Text: "Answer 1", Correct: true},
|
||
|
{Text: "Answer 2", Correct: false},
|
||
|
{Text: "Answer 3", Correct: false},
|
||
|
{Text: "Answer 4", Correct: false},
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
t.True(quiz.Hash != updatedQuiz.Hash, "The two hashes should not be equal.")
|
||
|
}
|