File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88 "github.com/github/gh-stack/internal/config"
99 "github.com/github/gh-stack/internal/git"
10+ "github.com/github/gh-stack/internal/github"
1011 "github.com/github/gh-stack/internal/stack"
1112 "github.com/stretchr/testify/assert"
1213 "github.com/stretchr/testify/require"
@@ -82,6 +83,7 @@ func TestPush_SkipPRs(t *testing.T) {
8283 defer restore ()
8384
8485 cfg , _ , errR := config .NewTestConfig ()
86+ cfg .GitHubClientOverride = & github.MockClient {}
8587 cmd := PushCmd (cfg )
8688 cmd .SetArgs ([]string {"--skip-prs" })
8789 cmd .SetOut (io .Discard )
@@ -124,6 +126,7 @@ func TestPush_SkipsMergedBranches(t *testing.T) {
124126 defer restore ()
125127
126128 cfg , _ , errR := config .NewTestConfig ()
129+ cfg .GitHubClientOverride = & github.MockClient {}
127130 cmd := PushCmd (cfg )
128131 cmd .SetArgs ([]string {"--skip-prs" })
129132 cmd .SetOut (io .Discard )
@@ -158,6 +161,7 @@ func TestPush_PushFailure(t *testing.T) {
158161 defer restore ()
159162
160163 cfg , _ , errR := config .NewTestConfig ()
164+ cfg .GitHubClientOverride = & github.MockClient {}
161165 cmd := PushCmd (cfg )
162166 cmd .SetArgs ([]string {"--skip-prs" })
163167 cmd .SetOut (io .Discard )
Original file line number Diff line number Diff line change 88
99 "github.com/github/gh-stack/internal/config"
1010 "github.com/github/gh-stack/internal/git"
11+ "github.com/github/gh-stack/internal/github"
1112 "github.com/github/gh-stack/internal/stack"
1213 "github.com/stretchr/testify/assert"
1314 "github.com/stretchr/testify/require"
@@ -43,6 +44,7 @@ func TestUnstack_RemovesStack(t *testing.T) {
4344 writeTwoStacks (t , gitDir , s1 , s2 )
4445
4546 cfg , outR , errR := config .NewTestConfig ()
47+ cfg .GitHubClientOverride = & github.MockClient {}
4648 err := runUnstack (cfg , & unstackOptions {})
4749 output := collectOutput (cfg , outR , errR )
4850
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ type Config struct {
2626 ColorMagenta func (string ) string
2727 ColorCyan func (string ) string
2828 ColorGray func (string ) string
29+
30+ // GitHubClientOverride, when non-nil, is returned by GitHubClient()
31+ // instead of creating a real client. Used in tests to inject a MockClient.
32+ GitHubClientOverride ghapi.ClientOps
2933}
3034
3135// New creates a new Config with terminal-aware output and color support.
@@ -109,7 +113,10 @@ func (c *Config) Repo() (repository.Repository, error) {
109113 return repository .Current ()
110114}
111115
112- func (c * Config ) GitHubClient () (* ghapi.Client , error ) {
116+ func (c * Config ) GitHubClient () (ghapi.ClientOps , error ) {
117+ if c .GitHubClientOverride != nil {
118+ return c .GitHubClientOverride , nil
119+ }
113120 repo , err := c .Repo ()
114121 if err != nil {
115122 return nil , fmt .Errorf ("determining repository: %w" , err )
You can’t perform that action at this time.
0 commit comments