1
0
mirror of https://github.com/strongdm/comply synced 2024-11-21 23:24:53 +00:00

Check generated documents in tests (#48)

This commit is contained in:
Rodolfo Campos 2021-10-12 14:46:30 +02:00
parent 1c80e1ce66
commit ad2c89ec67

View File

@ -16,18 +16,24 @@ import (
// TestReadNarratives calls model.ReadNarratives checking for a valid return value.
func TestReadNarratives(t *testing.T) {
mockConfig()
filePath := fmt.Sprintf("%s/narratives/control.md", getRootPath())
fileInfo, _ := os.Lstat(filePath)
path.Narratives = func() ([]path.File, error) {
filePath := fmt.Sprintf("%s/narratives/control.md", getRootPath())
fileInfo, _ := os.Lstat(filePath)
return []path.File{
{FullPath: filePath, Info: fileInfo},
}, nil
}
_, err := ReadNarratives()
documents, err := ReadNarratives()
if err != nil {
t.Fatalf(`ReadNarratives() returned an error %v`, err)
}
if len(documents) != 1 {
t.Fatal(`Invalid number of documents`)
}
if documents[0].FullPath != filePath {
t.Fatalf(`Invalid document path %s`, documents[0].FullPath)
}
}
// TestReadNarratives calls model.ReadNarratives checking for a valid return when
@ -38,10 +44,13 @@ func TestReadNarrativesWhenThereAreNoNarratives(t *testing.T) {
return []path.File{}, nil
}
_, err := ReadNarratives()
documents, err := ReadNarratives()
if err != nil {
t.Fatalf(`ReadNarratives() returned an error %v`, err)
}
if len(documents) != 0 {
t.Fatal(`Invalid number of documents`)
}
}
// TestReadNarratives calls model.ReadNarratives checking for an error return when