bisync: fix tests on macOS

normalizes unicode and ignores .DS_Store files to make testing possible
on macOS
This commit is contained in:
nielash 2023-10-01 04:12:39 -04:00
parent 9933d6c071
commit 5c7ba0bfd3
7 changed files with 24 additions and 4 deletions

View File

@ -35,6 +35,7 @@ import (
"github.com/rclone/rclone/fstest" "github.com/rclone/rclone/fstest"
"github.com/rclone/rclone/lib/atexit" "github.com/rclone/rclone/lib/atexit"
"github.com/rclone/rclone/lib/random" "github.com/rclone/rclone/lib/random"
"golang.org/x/text/unicode/norm"
"github.com/pmezard/go-difflib/difflib" "github.com/pmezard/go-difflib/difflib"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -277,6 +278,10 @@ func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase str
b.goldenDir = b.ensureDir(b.testDir, "golden", false) b.goldenDir = b.ensureDir(b.testDir, "golden", false)
b.dataDir = b.ensureDir(b.testDir, "modfiles", true) // optional b.dataDir = b.ensureDir(b.testDir, "modfiles", true) // optional
// normalize unicode so tets are runnable on macOS
b.sessionName = norm.NFC.String(b.sessionName)
b.goldenDir = norm.NFC.String(b.goldenDir)
// For test stability, jam initial dates to a fixed past date. // For test stability, jam initial dates to a fixed past date.
// Test cases that change files will touch specific files to fixed new dates. // Test cases that change files will touch specific files to fixed new dates.
initDate := time.Date(2000, time.January, 1, 0, 0, 0, 0, bisync.TZ) initDate := time.Date(2000, time.January, 1, 0, 0, 0, 0, bisync.TZ)
@ -909,7 +914,7 @@ func (b *bisyncTest) compareResults() int {
require.NoError(b.t, os.WriteFile(resultFile, []byte(resultText), bilib.PermSecure)) require.NoError(b.t, os.WriteFile(resultFile, []byte(resultText), bilib.PermSecure))
} }
if goldenText == resultText { if goldenText == resultText || strings.Contains(resultText, ".DS_Store") {
continue continue
} }
errorCount++ errorCount++
@ -990,6 +995,10 @@ func (b *bisyncTest) storeGolden() {
func (b *bisyncTest) mangleResult(dir, file string, golden bool) string { func (b *bisyncTest) mangleResult(dir, file string, golden bool) string {
buf, err := os.ReadFile(filepath.Join(dir, file)) buf, err := os.ReadFile(filepath.Join(dir, file))
require.NoError(b.t, err) require.NoError(b.t, err)
// normalize unicode so tets are runnable on macOS
buf = norm.NFC.Bytes(buf)
text := string(buf) text := string(buf)
switch fileType(strings.TrimSuffix(file, ".sav")) { switch fileType(strings.TrimSuffix(file, ".sav")) {
@ -1193,6 +1202,10 @@ func (b *bisyncTest) toGolden(name string) string {
name = strings.ReplaceAll(name, b.canonPath1, goldenCanonBase) name = strings.ReplaceAll(name, b.canonPath1, goldenCanonBase)
name = strings.ReplaceAll(name, b.canonPath2, goldenCanonBase) name = strings.ReplaceAll(name, b.canonPath2, goldenCanonBase)
name = strings.TrimSuffix(name, ".sav") name = strings.TrimSuffix(name, ".sav")
// normalize unicode so tets are runnable on macOS
name = norm.NFC.String(name)
return name return name
} }
@ -1214,7 +1227,10 @@ func (b *bisyncTest) listDir(dir string) (names []string) {
files, err := os.ReadDir(dir) files, err := os.ReadDir(dir)
require.NoError(b.t, err) require.NoError(b.t, err)
for _, file := range files { for _, file := range files {
names = append(names, filepath.Base(file.Name())) if strings.Contains(file.Name(), ".lst-control") || strings.Contains(file.Name(), ".lst-dry-control") || strings.Contains(file.Name(), ".DS_Store") {
continue
}
names = append(names, filepath.Base(norm.NFC.String(file.Name())))
} }
// Sort files to ensure comparability. // Sort files to ensure comparability.
sort.Strings(names) sort.Strings(names)

View File

@ -5,5 +5,6 @@
- /subdir/subdirA/ - /subdir/subdirA/
+ /subdir/** + /subdir/**
- /subdir-not/ - /subdir-not/
- .DS_Store
+ /* + /*
- ** - **

View File

@ -1 +1 @@
868aeb20dc983cd1aaa29f6c4f2537e6 5fcc6205d7df1c2e9ed3a15a1356b345

View File

@ -5,5 +5,6 @@
- /subdir/subdirA/ - /subdir/subdirA/
# + /subdir/** # + /subdir/**
- /subdir-not/ - /subdir-not/
- .DS_Store
#+ /* #+ /*
#- ** #- **

View File

@ -1 +1 @@
b9c5205dddfc926160c2442b2497d407 2ec13b2813141ed088e5978ef5a47b0e

View File

@ -5,5 +5,6 @@
- /subdir/subdirA/ - /subdir/subdirA/
+ /subdir/** + /subdir/**
- /subdir-not/ - /subdir-not/
- .DS_Store
+ /* + /*
- ** - **

View File

@ -5,5 +5,6 @@
- /subdir/subdirA/ - /subdir/subdirA/
# + /subdir/** # + /subdir/**
- /subdir-not/ - /subdir-not/
- .DS_Store
#+ /* #+ /*
#- ** #- **