Skip to content

Commit 42c6b67

Browse files
committed
fix: update test case
1 parent b04e778 commit 42c6b67

5 files changed

Lines changed: 107 additions & 7 deletions

File tree

github/github-accessors.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/strings_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func TestString(t *testing.T) {
107107
{Hook{ID: Ptr(int64(1))}, `github.Hook{ID:1}`},
108108
{IssueComment{ID: Ptr(int64(1))}, `github.IssueComment{ID:1}`},
109109
{Issue{Number: Ptr(1)}, `github.Issue{Number:1}`},
110+
{SubIssue{ID: Ptr(int64(1))}, `github.SubIssue{ID:1}`},
110111
{Key{ID: Ptr(int64(1))}, `github.Key{ID:1}`},
111112
{Label{ID: Ptr(int64(1)), Name: Ptr("l")}, `github.Label{ID:1, Name:"l"}`},
112113
{Organization{ID: Ptr(int64(1))}, `github.Organization{ID:1}`},

github/sub_issue.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ type SubIssueListByIssueOptions struct {
3838

3939
// SubIssueRequest represents a request to add, remove, or reprioritize sub-issues.
4040
type SubIssueRequest struct {
41-
SubIssueID int64 `json:"sub_issue_id"` // Required: The ID of the sub-issue
42-
AfterID *int64 `json:"after_id,omitempty"` // Optional: Position after this sub-issue ID
43-
BeforeID *int64 `json:"before_id,omitempty"` // Optional: Position before this sub-issue ID
44-
ReplaceParent *bool `json:"replace_parent,omitempty"` // Optional: Whether to replace the existing parent
41+
SubIssueID int64 `json:"sub_issue_id"` // Required: The ID of the sub-issue
42+
AfterID *int64 `json:"after_id,omitempty"` // Optional: Position after this sub-issue ID
43+
BeforeID *int64 `json:"before_id,omitempty"` // Optional: Position before this sub-issue ID
44+
ReplaceParent *bool `json:"replace_parent,omitempty"` // Optional: Whether to replace the existing parent
4545
}
4646

4747
// Remove a sub-issue from the specified repository.
4848
//
4949
// GitHub API docs: https://docs.github.com/rest/issues/sub-issues#remove-sub-issue
5050
//
5151
//meta:operation DELETE /repos/{owner}/{repo}/issues/{issue_number}/sub_issue
52-
func (s *SubIssueService) Remove(ctx context.Context, owner, repo string, subIssueNumber int64, subIssue SubIssueRequest) (*SubIssue, *Response, error) {
52+
func (s *SubIssueService) Remove(ctx context.Context, owner, repo string, subIssueNumber int64, subIssue *SubIssueRequest) (*SubIssue, *Response, error) {
5353
u := fmt.Sprintf("repos/%v/%v/issues/%v/sub_issues", owner, repo, subIssueNumber)
5454

5555
req, err := s.client.NewRequest("DELETE", u, subIssue)
@@ -129,7 +129,7 @@ func (s *SubIssueService) Add(ctx context.Context, owner string, repo string, is
129129
// GitHub API docs: https://docs.github.com/rest/issues/sub-issues#reprioritize-sub-issue
130130
//
131131
//meta:operation PATCH /repos/{owner}/{repo}/issues/{issue_number}/sub_issues/priority
132-
func (s *SubIssueService) Reprioritize(ctx context.Context, owner, repo string, issueNumber int64, subIssue SubIssueRequest) (*SubIssue, *Response, error) {
132+
func (s *SubIssueService) Reprioritize(ctx context.Context, owner, repo string, issueNumber int64, subIssue *SubIssueRequest) (*SubIssue, *Response, error) {
133133
u := fmt.Sprintf("repos/%v/%v/issues/%d/sub_issues/priority", owner, repo, issueNumber)
134134
req, err := s.client.NewRequest("PATCH", u, subIssue)
135135
if err != nil {

github/sub_issue_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ func TestSubIssuesService_Add(t *testing.T) {
4343
if !cmp.Equal(got, want) {
4444
t.Errorf("SubIssues.Add = %+v, want %+v", got, want)
4545
}
46+
47+
const methodName = "Add"
48+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
49+
got, resp, err := client.SubIssue.Add(ctx, "o", "r", 1, input)
50+
if got != nil {
51+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
52+
}
53+
return resp, err
54+
})
4655
}
4756

4857
func TestSubIssuesService_ListByIssue(t *testing.T) {
@@ -67,6 +76,20 @@ func TestSubIssuesService_ListByIssue(t *testing.T) {
6776
if !cmp.Equal(issues, want) {
6877
t.Errorf("SubIssues.ListByIssue = %+v, want %+v", issues, want)
6978
}
79+
80+
const methodName = "ListByIssue"
81+
testBadOptions(t, methodName, func() (err error) {
82+
_, _, err = client.SubIssue.ListByIssue(ctx, "\n", "\n", 1, opt)
83+
return err
84+
})
85+
86+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
87+
got, resp, err := client.SubIssue.ListByIssue(ctx, "o", "r", 1, opt)
88+
if got != nil {
89+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
90+
}
91+
return resp, err
92+
})
7093
}
7194

7295
func TestSubIssuesService_Remove(t *testing.T) {
@@ -99,13 +122,22 @@ func TestSubIssuesService_Remove(t *testing.T) {
99122
if !cmp.Equal(got, want) {
100123
t.Errorf("SubIssues.Remove = %+v, want %+v", got, want)
101124
}
125+
126+
const methodName = "Remove"
127+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
128+
got, resp, err := client.SubIssue.Remove(ctx, "o", "r", 1, input)
129+
if got != nil {
130+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
131+
}
132+
return resp, err
133+
})
102134
}
103135

104136
func TestSubIssuesService_Reprioritize(t *testing.T) {
105137
t.Parallel()
106138
client, mux, _ := setup(t)
107139

108-
input := &SubIssueRequest{SubIssueID: 42, AfterID: 5}
140+
input := &SubIssueRequest{SubIssueID: 42, AfterID: Int64(5)}
109141

110142
mux.HandleFunc("/repos/o/r/issues/1/sub_issues/priority", func(w http.ResponseWriter, r *http.Request) {
111143
testMethod(t, r, "PATCH")
@@ -132,4 +164,14 @@ func TestSubIssuesService_Reprioritize(t *testing.T) {
132164
if !cmp.Equal(got, want) {
133165
t.Errorf("SubIssues.Reprioritize = %+v, want %+v", got, want)
134166
}
167+
168+
const methodName = "Reprioritize"
169+
170+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
171+
got, resp, err := client.SubIssue.Reprioritize(ctx, "o", "r", 1, input)
172+
if got != nil {
173+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
174+
}
175+
return resp, err
176+
})
135177
}

0 commit comments

Comments
 (0)