45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
|
package file
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"git.andreafazzi.eu/andrea/probo/models"
|
||
|
"git.andreafazzi.eu/andrea/probo/store"
|
||
|
"github.com/remogatto/prettytest"
|
||
|
)
|
||
|
|
||
|
type participantTestSuite struct {
|
||
|
prettytest.Suite
|
||
|
}
|
||
|
|
||
|
func (t *participantTestSuite) TestCreate() {
|
||
|
filePathConfig := FilePathConfig{"testdata/participants", "participant", ".json"}
|
||
|
pStore, err := NewParticipantFileStore(
|
||
|
&FileStoreConfig[*models.Participant, *store.ParticipantStore]{
|
||
|
FilePathConfig: filePathConfig,
|
||
|
IndexDirFunc: DefaultIndexDirFunc[*models.Participant, *store.ParticipantStore],
|
||
|
UnmarshalFunc: DefaultJSONUnmarshalFunc[*models.Participant, *store.ParticipantStore],
|
||
|
MarshalFunc: DefaultJSONMarshalFunc[*models.Participant, *store.ParticipantStore],
|
||
|
})
|
||
|
t.Nil(err)
|
||
|
|
||
|
if !t.Failed() {
|
||
|
p, err := pStore.Create(&models.Participant{
|
||
|
Lastname: "Doe",
|
||
|
Firstname: "John",
|
||
|
Attributes: map[string]string{"class": "1 D LIN"},
|
||
|
})
|
||
|
|
||
|
t.Nil(err)
|
||
|
|
||
|
defer os.Remove(pStore.GetPath(p))
|
||
|
|
||
|
if !t.Failed() {
|
||
|
exists, err := os.Stat(pStore.GetPath(p))
|
||
|
|
||
|
t.Nil(err)
|
||
|
t.Not(t.Nil(exists))
|
||
|
}
|
||
|
}
|
||
|
}
|