e7bf8a6842
fix golint issue small improvements ListMyRepos now receives a value instead of a pointer reverted makefile changes added sleep in order to increase CI stability resolved conflicts Use RepositoryMeta struct on Issues (#267) Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/267 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io> extend SearchUsers (#248) Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: spawn2kill <spawn2kill@noreply.gitea.io> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/248 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: lafriks <lafriks@noreply.gitea.io> Implement Repo Transfer (#264) fix test check version add TestRepoTransfer add TransferRepo Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/264 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: lafriks <lafriks@noreply.gitea.io> Add notifications (#226) Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: spawn2kill <spawn2kill@noreply.gitea.io> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/226 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: lafriks <lafriks@noreply.gitea.io> Use StateType (#265) use StateType Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/265 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: lafriks <lafriks@noreply.gitea.io> opt setDefaults on issue_comment trigger CI Trigger notification resolved conflicts Fix AddEmail (#260) Merge branch 'master' into fix-AddEMail Add ListIssueCommentOptions for optional param (#243) Merge branch 'master' into impruve-ListXIssueComments Remove ListUserIssues() ... (#262) Merge branch 'master' into rm-ListUserIssues correct version (#257) Merge branch 'master' into targed-version Extend Issue Struct (#258) fix extend IssueTest add Repository to Issue struct Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/258 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Merge branch 'master' into targed-version format code (#245) fix if test is to fast remove lgtm bot config (gitea handle this now) format code Add GetIssueComment (#216) Merge branch 'master' into update-comment-api Fix & Refactor UserApp Functions (#247) Merge branch 'master' into refactor-user-app Add SearchRepo API Call (#254) Merge branch 'master' into search_repo IssueSubscribtion: Check http Status responce (#242) Merge branch 'master' into impruve-issueWatch Refactor RepoWatch (#241) Merge branch 'master' into refactor-repoWatch Add ListMilestoneOption to ListRepoMilestones (#244) use StateType use PageSize adjut test since gitea bug got fixed (#gitea/10047) add TestMilestones add optional ListMilestoneOption format Add ListOptions struct (#249) same struct as in models/list_options.go add mising license header add ListOptions struct Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/249 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: lafriks <lafriks@noreply.gitea.io> [README] add import path (#239) add import path add import path to readme Changelog v0.11.0 (#235) Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/235 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: John Olheiser <john.olheiser@gmail.com> Add TestMyUser (#237) Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/237 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/239 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/244 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Merge branch 'master' into refactor-repoWatch Add ListOptions struct (#249) same struct as in models/list_options.go add mising license header add ListOptions struct Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/249 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: lafriks <lafriks@noreply.gitea.io> add TEST fix GetMyWatchedRepos [README] add import path (#239) add import path add import path to readme Changelog v0.11.0 (#235) Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/235 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: John Ol... Co-authored-by: Hilário Coelho <hilario.coelho@securityside.com> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/205 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net>
125 lines
4 KiB
Go
125 lines
4 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gitea
|
|
|
|
import (
|
|
"log"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestIssue is main func witch call all Tests for Issue API
|
|
// (to make sure they are on correct order)
|
|
func TestIssue(t *testing.T) {
|
|
c := newTestClient()
|
|
|
|
createIssue(t, c)
|
|
// Little sleep in order to give some time for gitea to properly store all information on database. Without this sleep, CI is a bit unstable
|
|
time.Sleep(100 * time.Millisecond)
|
|
editIssues(t, c)
|
|
listIssues(t, c)
|
|
}
|
|
|
|
func createIssue(t *testing.T, c *Client) {
|
|
log.Println("== TestCreateIssues ==")
|
|
|
|
user, err := c.GetMyUserInfo()
|
|
assert.NoError(t, err)
|
|
repo, _ := createTestRepo(t, "IssueTestsRepo", c)
|
|
|
|
createOne := func(title, body string, assignees []string, deadline *time.Time, milestone int64, labels []int64, closed, shouldFail bool) {
|
|
issue, e := c.CreateIssue(user.UserName, repo.Name, CreateIssueOption{
|
|
Title: title,
|
|
Body: body,
|
|
Assignees: assignees,
|
|
Deadline: deadline,
|
|
Milestone: milestone,
|
|
Labels: labels,
|
|
Closed: closed,
|
|
})
|
|
if shouldFail {
|
|
assert.Error(t, e)
|
|
return
|
|
}
|
|
assert.NoError(t, e)
|
|
assert.NotEmpty(t, issue)
|
|
assert.EqualValues(t, title, issue.Title)
|
|
assert.EqualValues(t, body, issue.Body)
|
|
assert.EqualValues(t, len(assignees), len(issue.Assignees))
|
|
for i, a := range issue.Assignees {
|
|
assert.EqualValues(t, assignees[i], a.UserName)
|
|
}
|
|
if milestone > 0 {
|
|
assert.EqualValues(t, milestone, issue.Milestone.ID)
|
|
}
|
|
assert.EqualValues(t, len(labels), len(issue.Labels))
|
|
if closed {
|
|
assert.False(t, issue.Closed.IsZero())
|
|
} else {
|
|
assert.Empty(t, issue.Closed)
|
|
}
|
|
}
|
|
|
|
nowTime := time.Now()
|
|
mile, _ := c.CreateMilestone(user.UserName, repo.Name, CreateMilestoneOption{Title: "mile1"})
|
|
label1, _ := c.CreateLabel(user.UserName, repo.Name, CreateLabelOption{Name: "Label1", Description: "a", Color: "#ee0701"})
|
|
label2, _ := c.CreateLabel(user.UserName, repo.Name, CreateLabelOption{Name: "Label2", Description: "b", Color: "#128a0c"})
|
|
|
|
createOne("First Issue", "", nil, nil, 0, nil, false, false)
|
|
createOne("Issue 2", "closed isn't it?", nil, nil, 0, nil, true, false)
|
|
createOne("Issue 3", "", nil, nil, 0, nil, true, false)
|
|
createOne("Feature: spam protect 4", "explain explain explain", []string{user.UserName}, &nowTime, 0, nil, true, false)
|
|
createOne("W 123", "", nil, &nowTime, mile.ID, nil, false, false)
|
|
createOne("First Issue", "", nil, nil, 0, nil, false, false)
|
|
createOne("Do it soon!", "is important!", []string{user.UserName}, &nowTime, mile.ID, []int64{label1.ID, label2.ID}, false, false)
|
|
createOne("Job Done", "you never know", nil, nil, mile.ID, []int64{label2.ID}, true, false)
|
|
createOne("", "you never know", nil, nil, mile.ID, nil, true, true)
|
|
}
|
|
|
|
func editIssues(t *testing.T, c *Client) {
|
|
log.Println("== TestEditIssues ==")
|
|
il, err := c.ListIssues(ListIssueOption{KeyWord: "soon"})
|
|
assert.NoError(t, err)
|
|
issue, err := c.GetIssue(il[0].Poster.UserName, il[0].Repository.Name, il[0].Index)
|
|
assert.NoError(t, err)
|
|
|
|
body := "123 test and go"
|
|
state := StateClosed
|
|
issueNew, err := c.EditIssue(issue.Poster.UserName, issue.Repository.Name, issue.Index, EditIssueOption{
|
|
Title: "Edited",
|
|
Body: &body,
|
|
State: &state,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, issue.ID, issueNew.ID)
|
|
assert.EqualValues(t, body, issueNew.Body)
|
|
assert.EqualValues(t, "Edited", issueNew.Title)
|
|
}
|
|
|
|
func listIssues(t *testing.T, c *Client) {
|
|
log.Println("== TestListIssues ==")
|
|
|
|
issues, err := c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{
|
|
Labels: []string{"Label2"},
|
|
KeyWord: "",
|
|
State: "all",
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, issues, 2)
|
|
|
|
issues, err = c.ListIssues(ListIssueOption{
|
|
Labels: []string{"Label2"},
|
|
KeyWord: "Done",
|
|
State: "all",
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, issues, 1)
|
|
|
|
issues, err = c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, issues, 3)
|
|
}
|