MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / TestScanFiles

Function TestScanFiles

cmd/code2context/code_test.go:13–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestScanFiles(t *testing.T) {
14 // Create temp directory with test files
15 tmpDir := t.TempDir()
16
17 // Create test files
18 file1 := filepath.Join(tmpDir, "test1.go")
19 file2 := filepath.Join(tmpDir, "test2.go")
20 subDir := filepath.Join(tmpDir, "subdir")
21 file3 := filepath.Join(subDir, "test3.go")
22
23 require.NoError(t, os.WriteFile(file1, []byte("package main\n"), 0644))
24 require.NoError(t, os.WriteFile(file2, []byte("package main\n\nfunc main() {}\n"), 0644))
25 require.NoError(t, os.MkdirAll(subDir, 0755))
26 require.NoError(t, os.WriteFile(file3, []byte("package subdir\n"), 0644))
27
28 // Test scanning specific files
29 files := []string{file1, file3}
30 instructions := "Test instructions"
31
32 jsonData, err := ScanFiles(files, instructions)
33 require.NoError(t, err)
34
35 // Parse the JSON output
36 var result []any
37 err = json.Unmarshal(jsonData, &result)
38 require.NoError(t, err)
39 assert.Len(t, result, 3) // directory, report, instructions
40
41 // Check report
42 report := result[1].(map[string]any)
43 assert.Equal(t, "report", report["type"])
44 assert.Equal(t, float64(2), report["files"])
45
46 // Check instructions
47 instr := result[2].(map[string]any)
48 assert.Equal(t, "instructions", instr["type"])
49 assert.Equal(t, "Test instructions", instr["details"])
50}
51
52func TestScanFilesSkipsDirectories(t *testing.T) {
53 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 1

ScanFilesFunction · 0.85

Tested by

no test coverage detected