chore: fix test on new git
when default branch is main
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "strings"
"testing"
"github.com/jenkins-x/go-scm/scm"
@@ -102,6 +103,7 @@ func assertNoScmFileExists(t *testing.T, files []*scm.FileEntry, name, message s
}
func TestGitFileBrowser_Clone_CreateTag_FetchRef(t *testing.T) {
+
logger := logrus.WithField("client", "git")
baseDir, err := ioutil.TempDir("", "localdir")
@@ -125,6 +127,17 @@ func TestGitFileBrowser_Clone_CreateTag_FetchRef(t *testing.T) {
executor, err := git.NewCensoringExecutor(repoDir, censor, logger)
require.NoError(t, err, "failed to find git binary")
+ // lets fetch the default branch
+ defaultBranch := "master"
+ out, err := executor.Run("config", "--global", "--get", "init.defaultBranch")
+ if err == nil {
+ text := strings.TrimSpace(string(out))
+ if text != "" {
+ defaultBranch = text
+ }
+ }
+ t.Logf("using default branch: %s\n", defaultBranch)
+
err = ioutil.WriteFile(filepath.Join(repoDir, "README.md"), []byte("README"), 0600)
require.NoError(t, err, "failed to write README.md file")
@@ -141,7 +154,7 @@ func TestGitFileBrowser_Clone_CreateTag_FetchRef(t *testing.T) {
require.NoError(t, err, "failed to create git client factory")
fb := filebrowser.NewFileBrowserFromGitClient(cf)
- files, err := fb.ListFiles("org", "repo", "", "master", fc)
+ files, err := fb.ListFiles("org", "repo", "", defaultBranch, fc)
require.NoError(t, err, "failed to list files")
require.True(t, len(files) == 1, "exepecting 1 file")
