From c13d01913ccb8d0a4f7a27ab8cc76db1e601db02 Mon Sep 17 00:00:00 2001 From: Georg Date: Fri, 22 Dec 2023 09:48:46 +0100 Subject: [PATCH] Fix windows tests (#4) --- .changes/unreleased/Fixed-20231220-212936.yaml | 3 +++ .github/workflows/build-and-test.yml | 2 +- internal/pkg/batchconvert/batchconvert_test.go | 5 ++++- internal/pkg/settings/testfiles/config.yml | 2 +- pkg/parser/common_test.go | 6 +++++- 5 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231220-212936.yaml diff --git a/.changes/unreleased/Fixed-20231220-212936.yaml b/.changes/unreleased/Fixed-20231220-212936.yaml new file mode 100644 index 0000000..9853cb5 --- /dev/null +++ b/.changes/unreleased/Fixed-20231220-212936.yaml @@ -0,0 +1,3 @@ +kind: Fixed +body: Fix Windows tests +time: 2023-12-20T21:29:36.737004753+01:00 diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 3b879c5..57e71dd 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -14,7 +14,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, macos-latest] # "windows-latest" needs to be fixed, before enabling + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: diff --git a/internal/pkg/batchconvert/batchconvert_test.go b/internal/pkg/batchconvert/batchconvert_test.go index 90bb854..b19d953 100644 --- a/internal/pkg/batchconvert/batchconvert_test.go +++ b/internal/pkg/batchconvert/batchconvert_test.go @@ -7,6 +7,7 @@ import ( "path/filepath" "reflect" "sort" + "strings" "testing" "time" @@ -79,7 +80,9 @@ func areFilesEqual(file1, file2 string) (bool, error) { return false, err } - return string(content1) == string(content2), nil + // Trim possible all line endings to avoid differences on Windows + // and with git autocrlf settings + return strings.ReplaceAll(string(content1), "\r", "") == strings.ReplaceAll(string(content2), "\r", ""), nil } func extractFileNames(paths []string) []string { diff --git a/internal/pkg/settings/testfiles/config.yml b/internal/pkg/settings/testfiles/config.yml index 5fb1ce4..7717096 100644 --- a/internal/pkg/settings/testfiles/config.yml +++ b/internal/pkg/settings/testfiles/config.yml @@ -2,7 +2,7 @@ batchconvert: sets: - name: "name1" inputdir: "/my/path11" - outputdir: "/my/path12" + outputdir: "/my/path12" fileglobpattern: "*.csv" filemaxagedays: 5 format: "Barclaycard" diff --git a/pkg/parser/common_test.go b/pkg/parser/common_test.go index 26a3c68..608fddd 100644 --- a/pkg/parser/common_test.go +++ b/pkg/parser/common_test.go @@ -2,6 +2,7 @@ package parser import ( "os" + "strings" ) func areFilesEqual(file1, file2 string) bool { @@ -13,5 +14,8 @@ func areFilesEqual(file1, file2 string) bool { if err != nil { return false } - return string(file1Data) == string(file2Data) + + // Trim possible all line endings to avoid differences on Windows + // and with git autocrlf settings + return strings.ReplaceAll(string(file1Data), "\r", "") == strings.ReplaceAll(string(file2Data), "\r", "") }