(maint) fix unit tests so they pass on windows

This commit is contained in:
TP Honey 2022-06-13 17:46:57 +01:00
parent f7a3c375a2
commit 784c2e9e26
2 changed files with 20 additions and 3 deletions

View file

@ -2,6 +2,8 @@ package jsonnet
import (
"io/ioutil"
"runtime"
"strings"
"testing"
"github.com/drone/drone/core"
@ -82,13 +84,19 @@ func TestParseJsonnetNotTemplateFile(t *testing.T) {
req.Repo.Config = "plugin.jsonnet"
req.Config.Data = string(before)
parsedFile, err := Parse(req, nil, 0, nil, nil)
got, err := Parse(req, nil, 0, nil, nil)
if err != nil {
t.Error(err)
return
}
if want, got := parsedFile, string(after); want != got {
want := string(after)
// on windows line endings are \r\n, lets change them to linux for comparison
if runtime.GOOS == "windows" {
want = strings.Replace(want, "\r\n", "\n", -1)
}
if want != got {
t.Errorf("Want %q got %q", want, got)
}
}

View file

@ -17,6 +17,8 @@ package converter
import (
"encoding/json"
"io/ioutil"
"runtime"
"strings"
"testing"
"github.com/drone/drone/core"
@ -234,7 +236,14 @@ func TestTemplatePluginConvertJsonnet(t *testing.T) {
return
}
if want, got := config.Data, string(after); want != got {
want := string(after)
// on windows line endings are \r\n, lets change them to linux for comparison
if runtime.GOOS == "windows" {
want = strings.Replace(want, "\r\n", "\n", -1)
}
got := config.Data
if want != got {
t.Errorf("Want %q got %q", want, got)
}
}