MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestValidateFileAccess

Function TestValidateFileAccess

cmd/gosqlx/cmd/integration_test.go:226–267  ·  view source on GitHub ↗

TestValidateFileAccess tests the file access validation

(t *testing.T)

Source from the content-addressed store, hash-verified

224
225// TestValidateFileAccess tests the file access validation
226func TestValidateFileAccess(t *testing.T) {
227 tmpDir := t.TempDir()
228
229 // Test 1: Valid file
230 t.Run("ValidFile", func(t *testing.T) {
231 testFile := filepath.Join(tmpDir, "valid.sql")
232 err := os.WriteFile(testFile, []byte("SELECT 1"), 0644)
233 if err != nil {
234 t.Fatalf("Failed to create test file: %v", err)
235 }
236
237 err = ValidateFileAccess(testFile)
238 if err != nil {
239 t.Errorf("Expected success for valid file, got error: %v", err)
240 }
241 })
242
243 // Test 2: Directory
244 t.Run("Directory", func(t *testing.T) {
245 err := ValidateFileAccess(tmpDir)
246 if err == nil {
247 t.Error("Expected error for directory, got success")
248 }
249 // Accept either "directory" or "not a regular file" error messages
250 if !strings.Contains(err.Error(), "directory") && !strings.Contains(err.Error(), "not a regular file") {
251 t.Errorf("Expected directory or regular file error message, got: %v", err)
252 }
253 })
254
255 // Test 3: Nonexistent file
256 t.Run("NonexistentFile", func(t *testing.T) {
257 nonexistent := filepath.Join(tmpDir, "nonexistent.sql")
258 err := ValidateFileAccess(nonexistent)
259 if err == nil {
260 t.Error("Expected error for nonexistent file, got success")
261 }
262 // Accept either "cannot access file" or "invalid file path" error messages
263 if !strings.Contains(err.Error(), "cannot access file") && !strings.Contains(err.Error(), "invalid file path") {
264 t.Errorf("Expected access or path error message, got: %v", err)
265 }
266 })
267}
268
269// TestMemoryManagement tests that AST objects are properly released
270func TestMemoryManagement(t *testing.T) {

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
ValidateFileAccessFunction · 0.70
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected