IssueUn-/Subscription take care of new 200 status (#325)

IssueUn-/Subscription handle 200 status

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/325
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
This commit is contained in:
6543 2020-05-11 15:28:10 +00:00 committed by lafriks
parent 7ae928fbc2
commit fb7355a186
2 changed files with 10 additions and 1 deletions

View file

@ -30,6 +30,9 @@ func (c *Client) AddIssueSubscription(owner, repo string, index int64, user stri
if status == http.StatusCreated { if status == http.StatusCreated {
return nil return nil
} }
if status == http.StatusOK {
return fmt.Errorf("already subscribed")
}
return fmt.Errorf("unexpected Status: %d", status) return fmt.Errorf("unexpected Status: %d", status)
} }
@ -45,6 +48,9 @@ func (c *Client) DeleteIssueSubscription(owner, repo string, index int64, user s
if status == http.StatusCreated { if status == http.StatusCreated {
return nil return nil
} }
if status == http.StatusOK {
return fmt.Errorf("already unsubscribed")
}
return fmt.Errorf("unexpected Status: %d", status) return fmt.Errorf("unexpected Status: %d", status)
} }

View file

@ -29,7 +29,10 @@ func TestIssueSubscription(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, wi.Subscribed) assert.True(t, wi.Subscribed)
assert.NoError(t, c.IssueSubscribe(repo.Owner.UserName, repo.Name, 1)) err = c.IssueSubscribe(repo.Owner.UserName, repo.Name, 1)
if assert.Error(t, err) {
assert.EqualValues(t, "already subscribed", err.Error())
}
wi, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1) wi, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, wi.Subscribed) assert.True(t, wi.Subscribed)