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 02dcaa4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion 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,7 +35,7 @@ func compareFiles(pathA, pathB string) error {
if err != nil {
return err
}
if !bytes.Equal(contentA, contentB) {
if !bytes.Equal(ensureLF(contentA), ensureLF(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 02dcaa4

Please sign in to comment.