1
0
mirror of https://github.com/strongdm/comply synced 2024-11-05 23:45:25 +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. // TestReadNarratives calls model.ReadNarratives checking for a valid return value.
func TestReadNarratives(t *testing.T) { func TestReadNarratives(t *testing.T) {
mockConfig() mockConfig()
path.Narratives = func() ([]path.File, error) {
filePath := fmt.Sprintf("%s/narratives/control.md", getRootPath()) filePath := fmt.Sprintf("%s/narratives/control.md", getRootPath())
fileInfo, _ := os.Lstat(filePath) fileInfo, _ := os.Lstat(filePath)
path.Narratives = func() ([]path.File, error) {
return []path.File{ return []path.File{
{FullPath: filePath, Info: fileInfo}, {FullPath: filePath, Info: fileInfo},
}, nil }, nil
} }
_, err := ReadNarratives() documents, err := ReadNarratives()
if err != nil { if err != nil {
t.Fatalf(`ReadNarratives() returned an error %v`, err) 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 // TestReadNarratives calls model.ReadNarratives checking for a valid return when
@ -38,10 +44,13 @@ func TestReadNarrativesWhenThereAreNoNarratives(t *testing.T) {
return []path.File{}, nil return []path.File{}, nil
} }
_, err := ReadNarratives() documents, err := ReadNarratives()
if err != nil { if err != nil {
t.Fatalf(`ReadNarratives() returned an error %v`, err) 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 // TestReadNarratives calls model.ReadNarratives checking for an error return when