probo/store/memory/participant_test.go

63 lines
1.7 KiB
Go
Raw Permalink Normal View History

package memory
import (
"fmt"
"git.andreafazzi.eu/andrea/probo/client"
"git.andreafazzi.eu/andrea/probo/hasher/sha256"
"github.com/remogatto/prettytest"
)
type participantTestSuite struct {
prettytest.Suite
}
func (t *participantTestSuite) TestUpdateParticipant() {
store := NewMemoryProboCollectorStore(
sha256.NewDefault256Hasher(sha256.DefaultSHA256HashingFn),
)
participant, _ := store.CreateParticipant(&client.CreateUpdateParticipantRequest{
Participant: &client.Participant{
Firstname: "John",
Lastname: "Doe",
Token: 1234,
},
})
updatedParticipant, updated, err := store.UpdateParticipant(&client.CreateUpdateParticipantRequest{
Participant: &client.Participant{
Firstname: "Jack",
Lastname: "Smith",
},
}, participant.ID)
t.Nil(err, fmt.Sprintf("The update returned an error: %v", err))
if !t.Failed() {
t.True(updated)
t.Equal("Jack", updatedParticipant.Firstname)
}
}
func (t *participantTestSuite) TestDeleteParticipant() {
store := NewMemoryProboCollectorStore(
sha256.NewDefault256Hasher(sha256.DefaultSHA256HashingFn),
)
participant, _ := store.CreateParticipant(
&client.CreateUpdateParticipantRequest{
Participant: &client.Participant{
Firstname: "Jack",
Lastname: "Smith",
},
})
deletedParticipant, err := store.DeleteParticipant(&client.DeleteParticipantRequest{ID: participant.ID})
t.Equal(participant.ID, deletedParticipant.ID, "Returned deleted participant ID should be equal to the request")
t.Nil(err, fmt.Sprintf("The update returned an error: %v", err))
_, err = store.ReadParticipantByID(deletedParticipant.ID)
t.True(err != nil, "Reading a non existent participant should return an error")
}