Skip to content

Commit

Permalink
Fix errcheck issues in server/channels/utils/fileutils/fileutils_test…
Browse files Browse the repository at this point in the history
  • Loading branch information
shraddha761 authored Oct 25, 2024
1 parent 323e330 commit ca84f9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 0 additions & 1 deletion server/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ issues:
channels/store/storetest/thread_store.go|\
channels/store/storetest/user_store.go|\
channels/testlib/helper.go|\
channels/utils/fileutils/fileutils_test.go|\
channels/utils/license_test.go|\
channels/web/oauth.go|\
channels/web/oauth_test.go|\
Expand Down
20 changes: 14 additions & 6 deletions server/channels/utils/fileutils/fileutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func TestFindFile(t *testing.T) {
// tmpDir5/
tmpDir1, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(tmpDir1)
defer func() {
err = os.RemoveAll(tmpDir1)
require.NoError(t, err)
}()

tmpDir2, err := os.MkdirTemp(tmpDir1, "")
require.NoError(t, err)
Expand All @@ -52,10 +55,10 @@ func TestFindFile(t *testing.T) {
}

testCases := []testCase{}

for _, fileName := range []string{"file1.json", "file2.xml", "other.txt"} {
filePath := filepath.Join(tmpDir1, fileName)
require.NoError(t, os.WriteFile(filePath, []byte("{}"), 0600))
err = os.WriteFile(filePath, []byte("{}"), 0600)
require.NoError(t, err)

// Relative paths end up getting symlinks fully resolved, so use this below as necessary.
filePathResolved, err := filepath.EvalSymlinks(filePath)
Expand Down Expand Up @@ -112,10 +115,15 @@ func TestFindFile(t *testing.T) {
if testCase.Cwd != nil {
prevDir, err := os.Getwd()
require.NoError(t, err)
defer os.Chdir(prevDir)
os.Chdir(*testCase.Cwd)
}

err = os.Chdir(*testCase.Cwd)
require.NoError(t, err)

defer func() {
err = os.Chdir(prevDir)
require.NoError(t, err)
}()
}
assert.Equal(t, testCase.Expected, FindFile(testCase.FileName))
})
}
Expand Down

0 comments on commit ca84f9a

Please sign in to comment.