package main import ( "os" "path/filepath" "testing" "github.com/stretchr/testify/assert" ) func TestHomeDirectoryPatternExpansion(t *testing.T) { testDir := getTestSubDir(t) // Ensure we're working within the project directory ensureInProjectDir(t, testDir) // Change to test directory originalDir, _ := os.Getwd() defer os.Chdir(originalDir) os.Chdir(testDir) // Get the actual home directory homeDir, err := os.UserHomeDir() assert.NoError(t, err) // Create a test directory in the home folder testHomeDir := filepath.Join(homeDir, "synclib_test") err = os.MkdirAll(testHomeDir, 0755) assert.NoError(t, err) defer os.RemoveAll(testHomeDir) // Cleanup // Create a test file in the home directory testFile := filepath.Join(testHomeDir, "testhome.csv") err = os.WriteFile(testFile, []byte("test content"), 0644) assert.NoError(t, err) // Test the pattern with ~/ that should match the file pattern := "~/synclib_test/testhome.csv" links, err := ExpandPattern(pattern, testDir, "target.csv") // This should work but currently fails due to the bug assert.NoError(t, err) assert.Equal(t, 1, len(links), "Pattern should match exactly 1 file") if len(links) > 0 { assert.Contains(t, links[0].Source, "testhome.csv") assert.Equal(t, "target.csv", links[0].Target) } }