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