Skip to content

Commit

Permalink
fix: convert CRLF to LF when comparing files
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Mar 18, 2019
1 parent 2974b48 commit 03a7ef2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cobra/cmd/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 03a7ef2

Please sign in to comment.