Skip to content

Commit

Permalink
Move from float64 to int64 as return value in FileSizeInBytes method
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborpongracz committed Aug 1, 2024
1 parent 8f76e9c commit 10c3c48
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions fileutil/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type FileManager interface {
RemoveAll(path string) error
Write(path string, value string, perm os.FileMode) error
WriteBytes(path string, value []byte) error
FileSizeInBytes(pth string) (float64, error)
FileSizeInBytes(pth string) (int64, error)
}

type fileManager struct {
Expand Down Expand Up @@ -92,14 +92,14 @@ func (f fileManager) WriteBytes(path string, value []byte) error {
}

// FileSizeInBytes checks if the provided path exists and return with the file size (bytes) using os.Lstat.
func (fileManager) FileSizeInBytes(pth string) (float64, error) {
func (fileManager) FileSizeInBytes(pth string) (int64, error) {
if pth == "" {
return 0, errors.New("No path provided")
}
fileInf, err := os.Lstat(pth)
fileInf, err := os.Stat(pth)
if err != nil {
return 0, err
}

return float64(fileInf.Size()), nil
return fileInf.Size(), nil
}
4 changes: 2 additions & 2 deletions fileutil/fileutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ func TestFileSizeInBytes(t *testing.T) {

fileSize, err := manager.FileSizeInBytes(tmpFilePath)
require.NoError(t, err)
require.Equal(t, float64(len([]byte(content))), fileSize)
require.Equal(t, int64(len([]byte(content))), fileSize)
}
})

t.Run("Failure when non-existing path", func(t *testing.T) {
tmpFilePath := filepath.Join(tmpDirPath, "dir-does-not-exist-2", "FileSizeInBytes-error.txt")
_, err := manager.FileSizeInBytes(tmpFilePath)
require.EqualError(t, err, "lstat "+tmpFilePath+": no such file or directory")
require.EqualError(t, err, "stat "+tmpFilePath+": no such file or directory")
})

t.Run("Failure when path is empty string", func(t *testing.T) {
Expand Down

0 comments on commit 10c3c48

Please sign in to comment.