Fix tests on Windows (#562)

* fix: replace `\` with `/` in git ref to fix `git_test.go` on windows

Paths on Windows use backslash (`\`) as directory separator and this breaks `TestGitFindRef()`.
Replacing `\` with `/` in git ref fixes that issue.

* fix: replace `gopkg.in/godo.v2/glob` with std library `path/filepath`

`github.com/go-godo/godo` lib has been last updated in 2016 and it also
depends on another outdated lib `github.com/MichaelTJones/walk` with
last update in 2016. This also fixes `permission_denied` errors on
Windows (and perhaps Linux in some specific cases). I'm not aware of
any performance improvement or drawback because of that change.
This commit is contained in:
hackercat 2021-03-13 01:23:03 +01:00 committed by GitHub
parent f29b1f2523
commit eb2774275f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -98,7 +98,8 @@ func findGitPrettyRef(head, root, sub string) (string, error) {
}
var pointsTo = strings.TrimSpace(string(bts))
if head == pointsTo {
name = strings.TrimPrefix(strings.Replace(path, root, "", 1), "/")
// On Windows paths are separated with backslash character so they should be replaced to provide proper git refs format
name = strings.TrimPrefix(strings.ReplaceAll(strings.Replace(path, root, "", 1), `\`, `/`), "/")
log.Debugf("HEAD matches %s", name)
}
return nil

View file

@ -13,7 +13,6 @@ import (
"github.com/robertkrimen/otto"
log "github.com/sirupsen/logrus"
"gopkg.in/godo.v2/glob"
)
var expressionPattern, operatorPattern *regexp.Regexp
@ -319,9 +318,9 @@ func vmFromJSON(vm *otto.Otto) {
func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
return func(vm *otto.Otto) {
_ = vm.Set("hashFiles", func(paths ...string) string {
var files []*glob.FileAsset
var files []string
for i := range paths {
newFiles, _, err := glob.Glob([]string{filepath.Join(rc.Config.Workdir, paths[i])})
newFiles, err := filepath.Glob(filepath.Join(rc.Config.Workdir, paths[i]))
if err != nil {
log.Errorf("Unable to glob.Glob: %v", err)
return ""
@ -330,7 +329,7 @@ func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
}
hasher := sha256.New()
for _, file := range files {
f, err := os.Open(file.Path)
f, err := os.Open(file)
if err != nil {
log.Errorf("Unable to os.Open: %v", err)
}