From 784c2e9e268a450cad70ba89a4699b045aa18d60 Mon Sep 17 00:00:00 2001 From: TP Honey Date: Mon, 13 Jun 2022 17:46:57 +0100 Subject: [PATCH] (maint) fix unit tests so they pass on windows --- plugin/converter/jsonnet/jsonnet_test.go | 12 ++++++++++-- plugin/converter/template_test.go | 11 ++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/plugin/converter/jsonnet/jsonnet_test.go b/plugin/converter/jsonnet/jsonnet_test.go index 04a2bb76..a9dec7e8 100644 --- a/plugin/converter/jsonnet/jsonnet_test.go +++ b/plugin/converter/jsonnet/jsonnet_test.go @@ -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) } } diff --git a/plugin/converter/template_test.go b/plugin/converter/template_test.go index 6151cc59..63937aad 100644 --- a/plugin/converter/template_test.go +++ b/plugin/converter/template_test.go @@ -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) } }