-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit_test.go
More file actions
59 lines (48 loc) · 1.08 KB
/
init_test.go
File metadata and controls
59 lines (48 loc) · 1.08 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
// cmd/init_test.go
package cmd_test
import (
"os"
"os/exec"
"path/filepath"
"testing"
"github.com/boneskull/gh-stack/internal/config"
"github.com/boneskull/gh-stack/internal/git"
)
func setupTestRepo(t *testing.T) string {
t.Helper()
dir := t.TempDir()
run := func(args ...string) {
cmd := exec.Command("git", args...)
cmd.Dir = dir
cmd.Run()
}
run("init")
run("config", "user.email", "test@test.com")
run("config", "user.name", "Test")
// Create main branch with initial commit
f := filepath.Join(dir, "README.md")
os.WriteFile(f, []byte("# Test"), 0644)
run("add", ".")
run("commit", "-m", "initial")
return dir
}
func TestInitCommand(t *testing.T) {
dir := setupTestRepo(t)
// Verify the config package works for init
g := git.New(dir)
cfg, err := config.New(g)
if err != nil {
t.Fatalf("New failed: %v", err)
}
err = cfg.SetTrunk("main")
if err != nil {
t.Fatalf("SetTrunk failed: %v", err)
}
trunk, err := cfg.GetTrunk()
if err != nil {
t.Fatalf("GetTrunk failed: %v", err)
}
if trunk != "main" {
t.Errorf("expected 'main', got %q", trunk)
}
}