fix(storage): reject empty key + nil ReadCloser on Get error

This commit is contained in:
2026-05-04 00:34:42 +08:00
parent 33838f1820
commit 547b339ed3
2 changed files with 30 additions and 2 deletions
+19
View File
@@ -52,3 +52,22 @@ func TestLocalFS_DeleteNonexistentIsNoop(t *testing.T) {
fs, _ := NewLocalFS(t.TempDir())
require.NoError(t, fs.Delete(context.Background(), "nope/nope.txt"))
}
func TestLocalFS_RejectEmptyKey(t *testing.T) {
fs, _ := NewLocalFS(t.TempDir())
_, err := fs.Put(context.Background(), "", bytes.NewReader(nil), "text/plain")
require.Error(t, err)
_, err = fs.Put(context.Background(), ".", bytes.NewReader(nil), "text/plain")
require.Error(t, err)
_, err = fs.Get(context.Background(), "")
require.Error(t, err)
require.Error(t, fs.Delete(context.Background(), ""))
}
func TestLocalFS_GetMissingFileReturnsNilCloser(t *testing.T) {
// 验证错误路径下不会返回 typed-nil io.ReadCloser
fs, _ := NewLocalFS(t.TempDir())
r, err := fs.Get(context.Background(), "missing/file.txt")
require.Error(t, err)
require.Nil(t, r)
}