test file not exist error
All checks were successful
Declarative Tests / test (push) Successful in 47s

This commit is contained in:
Matthew Rich 2024-03-24 22:06:08 -07:00
parent ce95306eb1
commit b57de00464
2 changed files with 14 additions and 1 deletions

View File

@ -160,7 +160,8 @@ func (f *File) Read(ctx context.Context) ([]byte, error) {
info, e := os.Stat(f.Path) info, e := os.Stat(f.Path)
if e != nil { if e != nil {
panic(e) f.State = "absent"
return nil, e
} }
f.Mtime = info.ModTime() f.Mtime = info.ModTime()

View File

@ -77,6 +77,18 @@ func TestReadFile(t *testing.T) {
assert.YAMLEq(t, expected, string(r)) assert.YAMLEq(t, expected, string(r))
} }
func TestReadFileError(t *testing.T) {
ctx := context.Background()
file, _ := filepath.Abs(filepath.Join(TempDir, "missingfile.txt"))
f := NewFile()
assert.NotEqual(t, nil, f)
f.Path = file
_, e := f.Read(ctx)
assert.True(t, os.IsNotExist(e))
assert.Equal(t, "absent", f.State)
}
func TestCreateFile(t *testing.T) { func TestCreateFile(t *testing.T) {
file, _ := filepath.Abs(filepath.Join(TempDir, "foo.txt")) file, _ := filepath.Abs(filepath.Join(TempDir, "foo.txt"))