From 98a22507ffa09169fb8485a80c6955cbb64789f7 Mon Sep 17 00:00:00 2001 From: KevRiver Date: Tue, 5 Nov 2024 16:55:53 +0900 Subject: [PATCH] add if-statement that replace CRLF on Windows --- e2e_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/e2e_test.go b/e2e_test.go index 53f4cc1a..0c05a4a3 100644 --- a/e2e_test.go +++ b/e2e_test.go @@ -6,6 +6,8 @@ import ( "encoding/json" "os" "path/filepath" + "runtime" + "strings" "testing" "github.com/humanlogio/humanlog/internal/pkg/config" @@ -38,6 +40,13 @@ func TestHarness(t *testing.T) { if err != nil { t.Fatalf("reading config: %v", err) } + + if runtime.GOOS == "windows" { + input = replaceCRLF(input, "\r\n", "\n") + want = replaceCRLF(want, "\r\n", "\n") + cfgjson = replaceCRLF(cfgjson, "\r\n", "\n") + } + var cfg config.Config if err := json.Unmarshal(cfgjson, &cfg); err != nil { t.Fatalf("unmarshaling config: %v", err) @@ -109,6 +118,11 @@ type byteranges struct { ranges []*byterange } +func replaceCRLF(org []byte, oldCRLF string, newCRLF string) []byte { + replaced := strings.ReplaceAll(string(org), oldCRLF, newCRLF) + return []byte(replaced) +} + func newByteRanges() *byteranges { return &byteranges{} }