mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 04:48:33 +07:00
Merge pull request #556 from u5surf/issues-555
Skip read lines from empty file
This commit is contained in:
@@ -35,6 +35,13 @@ func (l *Lines) Extract() ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stat, err := f.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if stat.Size() == 0 {
|
||||
return []string{}, nil
|
||||
}
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
@@ -103,6 +103,13 @@ func TestReadLinesFromFile(t *testing.T) {
|
||||
expected: "Morbi vitae nulla in dui lobortis consectetur. Integer nec tempus felis. Ut quis suscipit risus. Donec lobortis consequat nunc, in efficitur mi maximus ac. Sed id felis posuere, aliquam purus eget, faucibus augue.",
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "extract lines from file",
|
||||
fileName: "testdata/empty.txt",
|
||||
lineNumber: 0,
|
||||
expected: "",
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "extract lines from file",
|
||||
fileName: "testdata/noop.txt",
|
||||
|
||||
0
internal/reader/testdata/empty.txt
vendored
Normal file
0
internal/reader/testdata/empty.txt
vendored
Normal file
Reference in New Issue
Block a user