From 03a7ef25d6bf6328ea77bea981eab8eafc07a457 Mon Sep 17 00:00:00 2001 From: umarcor Date: Mon, 18 Mar 2019 21:12:13 +0100 Subject: [PATCH] fix: convert CRLF to LF when comparing files --- cobra/cmd/golden_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cobra/cmd/golden_test.go b/cobra/cmd/golden_test.go index 59a5a1c9f9..995e59d253 100644 --- a/cobra/cmd/golden_test.go +++ b/cobra/cmd/golden_test.go @@ -17,6 +17,11 @@ func init() { initCmd.SetOutput(new(bytes.Buffer)) } +// ensureLF converts any \r\n to \n +func ensureLF(content []byte) []byte { + return bytes.Replace(content, []byte("\r\n"), []byte("\n"), -1) +} + // compareFiles compares the content of files with pathA and pathB. // If contents are equal, it returns nil. // If not, it returns which files are not equal @@ -30,6 +35,8 @@ func compareFiles(pathA, pathB string) error { if err != nil { return err } + contentA = ensureLF(contentA) + contentB = ensureLF(contentB) if !bytes.Equal(contentA, contentB) { output := new(bytes.Buffer) output.WriteString(fmt.Sprintf("%q and %q are not equal!\n\n", pathA, pathB))