Repository navigation
Expand file tree
/
Copy pathintegration_test.go
More file actions
77 lines (70 loc) · 2.1 KB
/
Copy pathintegration_test.go
File metadata and controls
77 lines (70 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// integration_test.go
package main
import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
func TestIntegration_PreviewCommand(t *testing.T) {
binary := buildBinary(t)
cmd := exec.Command(binary, "preview", "HI", "--year", "2025")
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("preview command failed: %v\n%s", err, string(out))
}
output := string(out)
if !strings.Contains(output, "█") {
t.Error("expected filled blocks in preview output")
}
if !strings.Contains(output, "HI") {
t.Error("expected message in preview header")
}
}
func TestIntegration_GenerateCommand(t *testing.T) {
binary := buildBinary(t)
outputDir := filepath.Join(t.TempDir(), "test-repo")
cmd := exec.Command(binary, "generate", "HI",
"--year", "2025",
"--output", outputDir,
"--name", "Test User",
"--email", "test@example.com",
"--commits-per-day", "1",
"--preview=false",
)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("generate command failed: %v\n%s", err, string(out))
}
// Verify .git exists
if _, err := os.Stat(filepath.Join(outputDir, ".git")); err != nil {
t.Fatal("expected .git directory in output")
}
// Verify state file exists
if _, err := os.Stat(filepath.Join(outputDir, ".commit-canvas.json")); err != nil {
t.Fatal("expected .commit-canvas.json in output")
}
// Verify commits exist
gitCmd := exec.Command("git", "log", "--oneline")
gitCmd.Dir = outputDir
gitOut, err := gitCmd.CombinedOutput()
if err != nil {
t.Fatalf("git log failed: %v", err)
}
lines := strings.Split(strings.TrimSpace(string(gitOut)), "\n")
// "HI" has ~40 active cells, but some may fall outside the target year
if len(lines) < 20 {
t.Errorf("expected at least 20 commits for 'HI', got only %d", len(lines))
}
}
func buildBinary(t *testing.T) string {
t.Helper()
binary := filepath.Join(t.TempDir(), "commit-canvas")
cmd := exec.Command("go", "build", "-o", binary, ".")
// go test runs from module root for top-level test files — no cmd.Dir needed
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("build failed: %v\n%s", err, string(out))
}
return binary
}