Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: replace path.Join with filepath.Join for file system paths #414

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 12 additions & 11 deletions internal/web/test/auth_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package test

import (
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/rs/zerolog/log"
"github.com/stretchr/testify/require"
"github.com/thomiceli/opengist/internal/config"
"github.com/thomiceli/opengist/internal/db"
"os"
"os/exec"
"path"
"testing"
)

func TestRegister(t *testing.T) {
Expand Down Expand Up @@ -280,26 +281,26 @@ func TestGitOperations(t *testing.T) {
}

func clientGitClone(creds string, user string, url string) error {
return exec.Command("git", "clone", "http://"+creds+"@localhost:6157/"+user+"/"+url, path.Join(config.GetHomeDir(), "tmp", url)).Run()
return exec.Command("git", "clone", "http://"+creds+"@localhost:6157/"+user+"/"+url, filepath.Join(config.GetHomeDir(), "tmp", url)).Run()
}

func clientGitPush(url string) error {
f, err := os.Create(path.Join(config.GetHomeDir(), "tmp", url, "newfile.txt"))
f, err := os.Create(filepath.Join(config.GetHomeDir(), "tmp", url, "newfile.txt"))
if err != nil {
return err
}
f.Close()

_ = exec.Command("git", "-C", path.Join(config.GetHomeDir(), "tmp", url), "add", "newfile.txt").Run()
_ = exec.Command("git", "-C", path.Join(config.GetHomeDir(), "tmp", url), "commit", "-m", "new file").Run()
err = exec.Command("git", "-C", path.Join(config.GetHomeDir(), "tmp", url), "push", "origin", "master").Run()
_ = exec.Command("git", "-C", filepath.Join(config.GetHomeDir(), "tmp", url), "add", "newfile.txt").Run()
_ = exec.Command("git", "-C", filepath.Join(config.GetHomeDir(), "tmp", url), "commit", "-m", "new file").Run()
err = exec.Command("git", "-C", filepath.Join(config.GetHomeDir(), "tmp", url), "push", "origin", "master").Run()

_ = os.RemoveAll(path.Join(config.GetHomeDir(), "tmp", url))
_ = os.RemoveAll(filepath.Join(config.GetHomeDir(), "tmp", url))

return err
}

func clientCheckRepo(url string, file string) error {
_, err := os.ReadFile(path.Join(config.GetHomeDir(), "tmp", url, file))
_, err := os.ReadFile(filepath.Join(config.GetHomeDir(), "tmp", url, file))
return err
}
9 changes: 4 additions & 5 deletions internal/web/test/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http/httptest"
"net/url"
"os"
"path"
"path/filepath"
"reflect"
"runtime"
Expand All @@ -35,7 +34,7 @@ type TestServer struct {

func newTestServer() (*TestServer, error) {
s := &TestServer{
server: server.NewServer(true, path.Join(config.GetHomeDir(), "tmp", "sessions"), true),
server: server.NewServer(true, filepath.Join(config.GetHomeDir(), "tmp", "sessions"), true),
}

go s.start()
Expand Down Expand Up @@ -146,7 +145,7 @@ func Setup(t *testing.T) *TestServer {

config.SetupSecretKey()

git.ReposDirectory = path.Join("tests")
git.ReposDirectory = filepath.Join("tests")

config.C.IndexEnabled = false
config.C.LogLevel = "error"
Expand Down Expand Up @@ -205,7 +204,7 @@ func Teardown(t *testing.T, s *TestServer) {
err := db.TruncateDatabase()
require.NoError(t, err, "Could not truncate database")

err = os.RemoveAll(path.Join(config.GetHomeDir(), "tests"))
err = os.RemoveAll(filepath.Join(config.GetHomeDir(), "tests"))
require.NoError(t, err, "Could not remove repos directory")

if runtime.GOOS == "windows" {
Expand All @@ -214,7 +213,7 @@ func Teardown(t *testing.T, s *TestServer) {

time.Sleep(2 * time.Second)
}
err = os.RemoveAll(path.Join(config.GetHomeDir(), "tmp"))
err = os.RemoveAll(filepath.Join(config.GetHomeDir(), "tmp"))
require.NoError(t, err, "Could not remove tmp directory")

// err = os.RemoveAll(path.Join(config.C.OpengistHome, "testsindex"))
Expand Down
Loading