-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlink_test.go
More file actions
81 lines (62 loc) · 1.49 KB
/
link_test.go
File metadata and controls
81 lines (62 loc) · 1.49 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
78
79
80
81
// cmd/link_test.go
package cmd_test
import (
"testing"
"github.com/boneskull/gh-stack/internal/config"
"github.com/boneskull/gh-stack/internal/git"
)
func TestLinkPR(t *testing.T) {
dir := setupTestRepo(t)
g := git.New(dir)
cfg, _ := config.New(g)
trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
// Create and track a branch
g.CreateAndCheckout("feature-a")
cfg.SetParent("feature-a", trunk)
// Link a PR
err := cfg.SetPR("feature-a", 456)
if err != nil {
t.Fatalf("SetPR failed: %v", err)
}
// Verify
pr, err := cfg.GetPR("feature-a")
if err != nil {
t.Fatalf("GetPR failed: %v", err)
}
if pr != 456 {
t.Errorf("expected PR 456, got %d", pr)
}
}
func TestLinkRejectsUntrackedBranch(t *testing.T) {
dir := setupTestRepo(t)
g := git.New(dir)
cfg, _ := config.New(g)
trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
// Create untracked branch
g.CreateAndCheckout("untracked")
// Should not be tracked
_, err := cfg.GetParent("untracked")
if err == nil {
t.Error("branch should not be tracked")
}
}
func TestLinkOverwritesPR(t *testing.T) {
dir := setupTestRepo(t)
g := git.New(dir)
cfg, _ := config.New(g)
trunk, _ := g.CurrentBranch()
cfg.SetTrunk(trunk)
// Create and track a branch with PR
g.CreateBranch("feature-a")
cfg.SetParent("feature-a", trunk)
cfg.SetPR("feature-a", 100)
// Overwrite with new PR
cfg.SetPR("feature-a", 200)
// Verify new PR
pr, _ := cfg.GetPR("feature-a")
if pr != 200 {
t.Errorf("expected PR 200, got %d", pr)
}
}