go-sdk/gitea/issue_test.go
6543 6f491e70ae [Makefile] Add "test-instance"; Add "help" (#231)
PASSWORD_COMPLEXITY = off

fix test

Makefile: add "test-instance" (start a gitea instance for test)
and add a help menue

Fix ListIssue Functions (now respect ListIssueOption's) (#225)

fix test

add Test

add more test cases and fix

nice log

add Issue Tests

impruve

more Repo Tests and mv createTestRepo

introduce "createTestRepo" a standad func to create a repo for testing

add workaround

 * Update Dates
 * Fix ListIssueOption

Fix ListRepoPullRequests (#219)

add ToDo notice

add ListRepoPullRequests TEST

remove useless drone config emtrys

fmt

ping CI

add new Options from PR #217

use query params

Add some PR list options (#217)

Empty Commit

Add enums

Add some PR list options

Add test framework (#227)

[Extend] StopWatch struct & functions (#211)

add StopWatch struct & functions

[Add]  reaction struct and functions (#213)

add struct and functions

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>

[Add] issue Un-/Subscription function (#214)

fix lint

add issue subscription function

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>

[Add] GetBlob (#212)

fix header from PR 206

add GetBlob

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: 6543 <6543@noreply.gitea.io>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: 6543 <6543@noreply.gitea.io>

Add test framework (#227)

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>

Add some PR list options (#217)

Empty Commit

Add enums

Add some PR list options

Add test framework (#227)

[Extend] StopWatch struct & functions (#211)

add StopWatch struct & functions

[Add]  reaction struct and functions (#213)

add struct and functions

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>

[Add] issue Un-/Subscription function (#214)

fix lint

add issue subscription function

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>

[Add] GetBlob (#212)

fix header from PR 206

add GetBlob

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: 6543 <6543@noreply.gitea.io>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: 6543 <6543@noreply.gitea.io>

Add test framework (#227)

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-on: gitea/go-sdk#225
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: gitea/go-sdk#231
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
2020-01-26 07:22:57 +00:00

103 lines
3.2 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)
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 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, 4)
}