6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 19:09:45 +00:00

Fix failing windows tests

Fix incorrect filepath.join usage in building filepaths from URL
This commit is contained in:
Grzegorz Dlugoszewski
2025-08-11 23:03:09 +02:00
parent 0612421afc
commit 31fa76afb8
8 changed files with 57 additions and 39 deletions

View File

@@ -3,6 +3,7 @@ package git
import (
"errors"
"git-get/pkg/git/test"
"os"
"testing"
"github.com/stretchr/testify/assert"
@@ -57,7 +58,7 @@ func TestExists(t *testing.T) {
want: errDirNotExist,
}, {
name: "dir exists",
path: "/tmp/",
path: os.TempDir(),
want: nil,
},
}

View File

@@ -13,7 +13,7 @@ import (
const (
dotgit = ".git"
untracked = "??" // Untracked files are marked as "??" in git status output.
master = "master"
main = "main"
head = "HEAD"
)

View File

@@ -120,9 +120,9 @@ func TestCurrentBranch(t *testing.T) {
want: "main",
},
{
name: "only master branch",
name: "only main branch",
repoMaker: test.RepoWithCommit,
want: master,
want: main,
},
{
name: "checked out new branch",
@@ -163,19 +163,19 @@ func TestBranches(t *testing.T) {
want: []string{""},
},
{
name: "only master branch",
name: "only main branch",
repoMaker: test.RepoWithCommit,
want: []string{"master"},
want: []string{"main"},
},
{
name: "new branch",
repoMaker: test.RepoWithBranch,
want: []string{"feature/branch", "master"},
want: []string{"feature/branch", "main"},
},
{
name: "checked out new tag",
repoMaker: test.RepoWithTag,
want: []string{"master"},
want: []string{"main"},
},
}
@@ -204,7 +204,7 @@ func TestUpstream(t *testing.T) {
{
name: "empty",
repoMaker: test.RepoEmpty,
branch: "master",
branch: "main",
want: "",
},
// TODO: add wantErr
@@ -215,10 +215,10 @@ func TestUpstream(t *testing.T) {
want: "",
},
{
name: "master with upstream",
name: "main with upstream",
repoMaker: test.RepoWithBranchWithUpstream,
branch: "master",
want: "origin/master",
branch: "main",
want: "origin/main",
},
{
name: "branch with upstream",
@@ -260,7 +260,7 @@ func TestAheadBehind(t *testing.T) {
{
name: "fresh clone",
repoMaker: test.RepoWithBranchWithUpstream,
branch: "master",
branch: "main",
want: []int{0, 0},
},
{

View File

@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
)
@@ -17,17 +18,14 @@ func TempDir(t *testing.T, parent string) string {
// Automatically remove temp dir when the test is over.
t.Cleanup(func() {
err := os.RemoveAll(dir)
if err != nil {
t.Errorf("failed removing test repo %s", dir)
}
removeTestDir(t, dir)
})
return dir
}
func (r *Repo) init() {
err := run.Git("init", "--quiet", r.path).AndShutUp()
err := run.Git("init", "--quiet", "--initial-branch=main", r.path).AndShutUp()
checkFatal(r.t, err)
}
@@ -92,3 +90,17 @@ func checkFatal(t *testing.T, err error) {
t.Fatalf("failed making test repo: %+v", err)
}
}
// removeTestDir removes a test directory
func removeTestDir(t *testing.T, dir string) {
// Skip cleanup on Windows to avoid file locking issues in CI
// The CI runner environment is destroyed after tests anyway
if runtime.GOOS == "windows" {
return
}
err := os.RemoveAll(dir)
if err != nil {
t.Logf("warning: failed removing test repo %s: %v", dir, err)
}
}