grokkit/cmd/edit_test.go
Greg Gauthier 9927b1fb6a chore(build): add Makefile and tests for commands and utilities
- Introduced Makefile with targets for testing (all, coverage, agent-specific), building, installing, cleaning, and help
- Added unit and integration tests for agent command, edit command, and CleanCodeResponse function
- Refactored CleanCodeResponse to use regex for robust markdown fence removal in agent and client modules
- Ensured tests cover code cleaning, plan generation placeholders, and file editing functionality
2026-03-01 00:24:48 +00:00

31 lines
630 B
Go

package cmd
import (
"os"
"strings"
"testing"
)
func TestEditCommand(t *testing.T) {
tmpfile, err := os.CreateTemp("", "test_edit_*.go")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())
original := []byte("package main\n\nfunc hello() {}\n")
os.WriteFile(tmpfile.Name(), original, 0644)
cmd := rootCmd
cmd.SetArgs([]string{"edit", tmpfile.Name(), "add a comment at the top"})
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}
content, _ := os.ReadFile(tmpfile.Name())
if !strings.HasPrefix(string(content), "//") {
t.Errorf("Expected a comment at the very top. Got:\n%s", content)
}
}