Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(utils): test exists function #3007

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions libs/utils/fs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package utils

import (
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestExists(t *testing.T) {
// Create a temporary file for testing
tmpFile, err := os.CreateTemp("", "test")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i'd prefer if we use t.TempDir() here please https://pkg.go.dev/testing#T.TempDir

require.NoError(t, err)
defer os.Remove(tmpFile.Name())

tests := []struct {
name string
path string
expected bool
}{
{
name: "File exists",
path: tmpFile.Name(),
expected: true,
},
{
name: "File does not exist",
path: "nonexistentfile.xyz",
expected: false,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := Exists(tc.path)
require.Equal(t, tc.expected, result)
})
}
}