Skip to content

Conversation

calmh
Copy link
Member

@calmh calmh commented May 3, 2023

This fixes various test issues with Go 1.20, and adds builds and tests on Go 1.20.

  • Most tests rewritten to use fakefs where possible
  • Some tests that were already skipped, or dubious (invasive,
    unmaintainable, unclear what they even tested) have been removed
  • Some actual code rewritten to better support testing in fakefs, removing assumptions on the fstype being "basic" (e.g., when auto accepting folders)

Also fix for new Windows path handling, in separate commit, and some build changes.

n.b. no squashy-squishy on this one

This fixes various test issues with Go 1.20.

- Most tests rewritten to use fakefs where possible
- Some tests that were already skipped, or dubious (invasive,
  unmaintainable, unclear what they even tested) have been removed
- Some actual code rewritten to better support testing in fakefs

Co-authored-by: Eric P <eric@kastelo.net>
@rasa
Copy link
Member

rasa commented May 4, 2023

@calmh Sorry, I accidently pushed this to your branch. Should I revert 593ed7e ?

@calmh
Copy link
Member Author

calmh commented May 4, 2023

As it fails the tests, yeah, but I can remove it. Looks like the \\.\ stuff is not handled properly in 1.19, maybe not with the old code either.

@rasa
Copy link
Member

rasa commented May 4, 2023

@calmh Yeah, I only tested on 1.20.3. The \\.\ tests should be removed since they fail on 1.19. Sorry for the mixup.

@rasa
Copy link
Member

rasa commented May 4, 2023

@calm Here's the test rewritten to pass on 1.19 and 1.20. Commit to your PR?

diff --git a/lib/fs/basicfs.go b/lib/fs/basicfs.go
index 0ec8984ac..51e598ed2 100644
--- a/lib/fs/basicfs.go
+++ b/lib/fs/basicfs.go
@@ -68,11 +68,7 @@ func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
 	// This way in the tests, we get away without OS specific separators
 	// in the test configs.
 	sep := string(filepath.Separator)
-	if !strings.HasSuffix(root, sep) {
-		root = filepath.Dir(root + sep)
-	} else {
-		root = filepath.Dir(root)
-	}
+	root = filepath.Clean(filepath.Dir(root + sep))

 	// Attempt tilde expansion; leave unchanged in case of error
 	if path, err := ExpandTilde(root); err == nil {
diff --git a/lib/fs/basicfs_windows_test.go b/lib/fs/basicfs_windows_test.go
index 5526dd220..1cbed7479 100644
--- a/lib/fs/basicfs_windows_test.go
+++ b/lib/fs/basicfs_windows_test.go
@@ -23,18 +23,28 @@ func TestWindowsPaths(t *testing.T) {
 		expectedRoot string
 		expectedURI  string
 	}{
+		{`e:`, `\\?\e:\`, `e:\`},
 		{`e:\`, `\\?\e:\`, `e:\`},
+		{`e:\\`, `\\?\e:\`, `e:\`}, // failed on 1.20
+		{`\\?\e:`, `\\?\e:\`, `e:\`},
 		{`\\?\e:\`, `\\?\e:\`, `e:\`},
+		{`\\?\e:\\`, `\\?\e:\`, `e:\`}, // failed on 1.20
+		{`e:\x`, `\\?\e:\x`, `e:\x`},
+		{`e:\x\`, `\\?\e:\x`, `e:\x`},
+		{`e:\x\\`, `\\?\e:\x`, `e:\x`},
+		// {`\\.\e:`, `\\.\e:\`, `e:\`}, // fails on 1.19 but not on 1.20
+		// {`\\.\e:\`, `\\.\e:\`, `e:\`}, // fails on 1.19 but not on 1.20
+		// {`\\.\e:\\`, `\\.\e:\`, `e:\`}, // fails on 1.19 but not on 1.20
 		{`\\192.0.2.22\network\share`, `\\192.0.2.22\network\share`, `\\192.0.2.22\network\share`},
 	}

-	for _, testCase := range testCases {
+	for i, testCase := range testCases {
 		fs := newBasicFilesystem(testCase.input)
 		if fs.root != testCase.expectedRoot {
-			t.Errorf("root %q != %q", fs.root, testCase.expectedRoot)
+			t.Errorf("test %d: root: expected `%s`, got `%s`", i, testCase.expectedRoot, fs.root)
 		}
 		if fs.URI() != testCase.expectedURI {
-			t.Errorf("uri %q != %q", fs.URI(), testCase.expectedURI)
+			t.Errorf("test %d: uri: expected `%s`, got `%s`", i, testCase.expectedURI, fs.URI())
 		}
 	}

@calmh calmh marked this pull request as ready for review May 9, 2023 04:59
@calmh
Copy link
Member Author

calmh commented May 9, 2023

@rasa thanks I adopted your change into the relevant commit 👍

Copy link
Member

@er-pa er-pa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-test changes seem perfectly fine. The important bits of the test-related changes look good to me too.

@calmh calmh merged commit e136d11 into syncthing:main May 9, 2023
@calmh calmh deleted the testrefactor branch May 9, 2023 10:02
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label May 8, 2024
@syncthing syncthing locked and limited conversation to collaborators May 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants