grokkit/internal/analyze/analyze_test.go

51 lines
1.2 KiB
Go
Raw Normal View History

package analyze
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDiscoverSourceFiles(t *testing.T) {
tmpDir := t.TempDir()
// Create some source files
if err := os.WriteFile(filepath.Join(tmpDir, "main.go"), []byte("package main"), 0644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(tmpDir, "helper.go"), []byte("package main"), 0644); err != nil {
t.Fatal(err)
}
// Create a non-source file (should be ignored)
if err := os.WriteFile(filepath.Join(tmpDir, "notes.txt"), []byte("notes"), 0644); err != nil {
t.Fatal(err)
}
files, err := DiscoverSourceFiles(tmpDir)
assert.NoError(t, err)
assert.GreaterOrEqual(t, len(files), 2)
// Verify .txt was not included
for _, f := range files {
assert.False(t, strings.HasSuffix(f, ".txt"))
}
}
func TestBuildProjectContext(t *testing.T) {
tmpDir := t.TempDir()
files := []string{
filepath.Join(tmpDir, "main.go"),
filepath.Join(tmpDir, "cmd", "root.go"),
}
ctx := BuildProjectContext(tmpDir, files)
assert.Contains(t, ctx, "Project Root:")
assert.Contains(t, ctx, "Total source files discovered: 2")
assert.Contains(t, ctx, "Key files")
}