Skip to content

Commit b8f30db

Browse files
committed
add unit test for isSymlink
1 parent 5ede483 commit b8f30db

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

internal/config/types_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,23 @@ func TestTypes_isAllowedDirWithSymlink(t *testing.T) {
109109
require.False(t, result, "Symlink in allowed directory should return false")
110110
})
111111
}
112+
113+
func TestTypes_isSymlink(t *testing.T) {
114+
// create temp dir
115+
tempDir := t.TempDir()
116+
tempConf := tempDir + "test.conf"
117+
defer os.RemoveAll(tempDir)
118+
119+
t.Run("Test 1: File is not a symlink", func(t *testing.T) {
120+
filePath := tempConf
121+
err := os.WriteFile(filePath, []byte("test content"), 0o600)
122+
require.NoError(t, err)
123+
assert.False(t, isSymlink(filePath), "File is not a symlink")
124+
})
125+
t.Run("Test 2: File is a symlink", func(t *testing.T) {
126+
filePath := tempDir + "test_conf_link"
127+
err := os.Symlink(tempConf, filePath)
128+
require.NoError(t, err)
129+
assert.True(t, isSymlink(filePath), "File is a symlink")
130+
})
131+
}

0 commit comments

Comments
 (0)