test file not exist error
All checks were successful
Declarative Tests / test (push) Successful in 47s
All checks were successful
Declarative Tests / test (push) Successful in 47s
This commit is contained in:
parent
ce95306eb1
commit
b57de00464
@ -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()
|
||||||
|
@ -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"))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user