Skip to content

Commit e0f6019

Browse files
committed
Add test coverage for handling of broken symlinks
1 parent 889f777 commit e0f6019

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

internal/project/project_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,57 @@ func TestSymlinkLoop(t *testing.T) {
6363
assert.Panics(t, func() { FindProjects() }, "Infinite symlink loop encountered during project discovery")
6464
}
6565

66+
func TestBrokenSymlink(t *testing.T) {
67+
projectsPath := testDataPath.Join("Projects")
68+
symlinkPath := projectsPath.Join("test-symlink")
69+
symlinkTargetPath := projectsPath.Join("nonexistent")
70+
// The broken symlink must have the attributes of a folder in order to be effective in this test, so the target must
71+
// exist at the time the symlink is created.
72+
err := symlinkTargetPath.Mkdir()
73+
require.Nil(t, err)
74+
// Create a folder symlink in the projects folder.
75+
// It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
76+
err = os.Symlink(projectsPath.Join("nonexistent").String(), symlinkPath.String())
77+
require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.")
78+
defer symlinkPath.RemoveAll() // Clean up.
79+
80+
// Break the symlink.
81+
err = symlinkTargetPath.Remove()
82+
require.Nil(t, err)
83+
84+
flags := test.ConfigurationFlags()
85+
flags.Set("project-type", "all")
86+
flags.Set("recursive", "true")
87+
configuration.Initialize(flags, []string{projectsPath.String()})
88+
89+
foundProjects, err := FindProjects()
90+
require.Nil(t, err)
91+
assert.True(
92+
t,
93+
reflect.DeepEqual(
94+
foundProjects,
95+
[]Type{
96+
{
97+
Path: testDataPath.Join("Projects", "Library"),
98+
ProjectType: projecttype.Library,
99+
SuperprojectType: projecttype.Library,
100+
},
101+
{
102+
Path: testDataPath.Join("Projects", "Library", "examples", "Example"),
103+
ProjectType: projecttype.Sketch,
104+
SuperprojectType: projecttype.Library,
105+
},
106+
{
107+
Path: testDataPath.Join("Projects", "Sketch"),
108+
ProjectType: projecttype.Sketch,
109+
SuperprojectType: projecttype.Sketch,
110+
},
111+
},
112+
),
113+
"Broken symlink encountered during project discovery",
114+
)
115+
}
116+
66117
func TestFindProjects(t *testing.T) {
67118
sketchPath := testDataPath.Join("Sketch")
68119
libraryPath := testDataPath.Join("Library")

internal/rule/rulefunction/library_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ func TestLibraryContainsSymlinks(t *testing.T) {
135135
err = symlinkPath.RemoveAll()
136136
require.Nil(t, err)
137137

138+
// Set up a library with a broken symlink.
139+
err = os.Symlink(librariesTestDataPath.Join(testLibrary, "nonexistent").String(), symlinkPath.String())
140+
require.Nil(t, err)
141+
142+
testTables = []libraryRuleFunctionTestTable{
143+
{"Has broken symlink", testLibrary, ruleresult.Fail, ""},
144+
}
145+
146+
checkLibraryRuleFunction(LibraryContainsSymlinks, testTables, t)
147+
148+
err = symlinkPath.RemoveAll()
149+
require.Nil(t, err)
150+
138151
testTables = []libraryRuleFunctionTestTable{
139152
{"No symlink", testLibrary, ruleresult.Pass, ""},
140153
}

0 commit comments

Comments
 (0)