summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGarrett Ladley <[email protected]>2025-05-01 06:55:28 -0400
committeradamdottv <[email protected]>2025-05-01 11:08:06 -0500
commitfbca5441f659920730196245c4660a38839a2c0e (patch)
tree662044b3e123a77e74f6c30b73db97a00ab430c3
parente4680caebb7235988450f6b1d59da2e46a78e567 (diff)
downloadopencode-fbca5441f659920730196245c4660a38839a2c0e.tar.gz
opencode-fbca5441f659920730196245c4660a38839a2c0e.zip
feat: test for getContextFromPaths (#105)
* feat: test for getContextFromPaths * fix: use testify
-rw-r--r--internal/llm/prompt/prompt_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/llm/prompt/prompt_test.go b/internal/llm/prompt/prompt_test.go
new file mode 100644
index 000000000..405ad5194
--- /dev/null
+++ b/internal/llm/prompt/prompt_test.go
@@ -0,0 +1,57 @@
+package prompt
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/opencode-ai/opencode/internal/config"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestGetContextFromPaths(t *testing.T) {
+ t.Parallel()
+
+ tmpDir := t.TempDir()
+ _, err := config.Load(tmpDir, false)
+ if err != nil {
+ t.Fatalf("Failed to load config: %v", err)
+ }
+ cfg := config.Get()
+ cfg.WorkingDir = tmpDir
+ cfg.ContextPaths = []string{
+ "file.txt",
+ "directory/",
+ }
+ testFiles := []string{
+ "file.txt",
+ "directory/file_a.txt",
+ "directory/file_b.txt",
+ "directory/file_c.txt",
+ }
+
+ createTestFiles(t, tmpDir, testFiles)
+
+ context := getContextFromPaths()
+ expectedContext := fmt.Sprintf("# From:%s/file.txt\nfile.txt: test content\n# From:%s/directory/file_a.txt\ndirectory/file_a.txt: test content\n# From:%s/directory/file_b.txt\ndirectory/file_b.txt: test content\n# From:%s/directory/file_c.txt\ndirectory/file_c.txt: test content", tmpDir, tmpDir, tmpDir, tmpDir)
+ assert.Equal(t, expectedContext, context)
+}
+
+func createTestFiles(t *testing.T, tmpDir string, testFiles []string) {
+ t.Helper()
+ for _, path := range testFiles {
+ fullPath := filepath.Join(tmpDir, path)
+ if path[len(path)-1] == '/' {
+ err := os.MkdirAll(fullPath, 0755)
+ require.NoError(t, err)
+ } else {
+ dir := filepath.Dir(fullPath)
+ err := os.MkdirAll(dir, 0755)
+ require.NoError(t, err)
+ err = os.WriteFile(fullPath, []byte(path+": test content"), 0644)
+ require.NoError(t, err)
+ }
+ }
+}