mirror of
https://github.com/github/gh-stack.git
synced 2026-09-14 20:26:28 +08:00
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package github
|
|
|
|
import "fmt"
|
|
|
|
// MockClient is a test double for GitHub API operations.
|
|
// Each field is an optional function that, when set, handles the corresponding
|
|
// ClientOps method call. When nil, a reasonable default is returned.
|
|
type MockClient struct {
|
|
FindPRForBranchFn func(string) (*PullRequest, error)
|
|
FindAnyPRForBranchFn func(string) (*PullRequest, error)
|
|
FindPRDetailsForBranchFn func(string) (*PRDetails, error)
|
|
CreatePRFn func(string, string, string, string, bool) (*PullRequest, error)
|
|
DeleteStackFn func() error
|
|
}
|
|
|
|
// Compile-time check that MockClient satisfies ClientOps.
|
|
var _ ClientOps = (*MockClient)(nil)
|
|
|
|
func (m *MockClient) FindPRForBranch(branch string) (*PullRequest, error) {
|
|
if m.FindPRForBranchFn != nil {
|
|
return m.FindPRForBranchFn(branch)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *MockClient) FindAnyPRForBranch(branch string) (*PullRequest, error) {
|
|
if m.FindAnyPRForBranchFn != nil {
|
|
return m.FindAnyPRForBranchFn(branch)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *MockClient) FindPRDetailsForBranch(branch string) (*PRDetails, error) {
|
|
if m.FindPRDetailsForBranchFn != nil {
|
|
return m.FindPRDetailsForBranchFn(branch)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *MockClient) CreatePR(base, head, title, body string, draft bool) (*PullRequest, error) {
|
|
if m.CreatePRFn != nil {
|
|
return m.CreatePRFn(base, head, title, body, draft)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *MockClient) DeleteStack() error {
|
|
if m.DeleteStackFn != nil {
|
|
return m.DeleteStackFn()
|
|
}
|
|
return fmt.Errorf("deleting a stack on GitHub is not yet supported by the API")
|
|
}
|