本文整理匯總了Golang中k8s/io/contrib/mungegithub/github/testing.Issue函數的典型用法代碼示例。如果您正苦於以下問題:Golang Issue函數的具體用法?Golang Issue怎麽用?Golang Issue使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Issue函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestPRGetFixesList
func TestPRGetFixesList(t *testing.T) {
tests := []struct {
issue *github.Issue
body string
expected []int
}{
{
issue: github_test.Issue("", 1, []string{"label1"}, false),
body: `bla resolve
this pr closes #45545 and also fixes #679
bla, some more bla with close here and there.
some suggest that it resolved #5643`,
expected: []int{45545, 679, 5643},
},
{
issue: github_test.Issue("", 2, []string{"label1"}, false),
body: `bla resolve 345
some suggest that it also closes #892`,
expected: []int{892},
},
{
issue: github_test.Issue("", 3, []string{"label1"}, false),
body: `bla resolve
this pr closes and fixes nothing`,
expected: nil,
},
{
issue: github_test.Issue("", 4, []string{"label1"}, false),
body: `bla bla
this pr Fixes #23 and FIXES #45 but not fixxx #99`,
expected: []int{23, 45},
},
}
for testNum, test := range tests {
client, server, _ := github_test.InitServer(t, test.issue, nil, nil, nil, nil, nil, nil)
config := &Config{}
config.Org = "o"
config.Project = "r"
config.SetClient(client)
obj, err := config.GetObject(*test.issue.Number)
if err != nil {
t.Fatalf("%d: unable to get issue: %v", testNum, *test.issue.Number)
}
obj.Issue.Body = &test.body
fixes := obj.GetPRFixesList()
if len(test.expected) != len(fixes) {
t.Errorf("%d: len(fixes) not equal, expected: %v but got: %v", testNum, test.expected, fixes)
return
}
for i, n := range test.expected {
if n != fixes[i] {
t.Errorf("%d: expected fixes: %v but got fixes: %v", testNum, test.expected, fixes)
}
}
server.Close()
}
}
示例2: TestRemoveLabel
func TestRemoveLabel(t *testing.T) {
tests := []struct {
issue *github.Issue
remove string
expected []string
}{
{
issue: github_test.Issue("", 1, []string{"label1"}, false),
remove: "label1",
expected: []string{},
},
{
issue: github_test.Issue("", 1, []string{"label2", "label1"}, false),
remove: "label1",
expected: []string{"label2"},
},
{
issue: github_test.Issue("", 1, []string{"label2"}, false),
remove: "label1",
expected: []string{"label2"},
},
{
issue: github_test.Issue("", 1, []string{}, false),
remove: "label1",
expected: []string{},
},
}
for testNum, test := range tests {
client, server, mux := github_test.InitServer(t, test.issue, nil, nil, nil, nil, nil)
config := &Config{}
config.Org = "o"
config.Project = "r"
config.SetClient(client)
mux.HandleFunc(fmt.Sprintf("/repos/o/r/issues/1/labels/%s", test.remove), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
obj, err := config.GetObject(*test.issue.Number)
if err != nil {
t.Fatalf("%d: unable to get issue: %v", testNum, *test.issue.Number)
}
obj.RemoveLabel(test.remove)
if len(test.expected) != len(obj.Issue.Labels) {
t.Errorf("%d: len(labels) not equal, expected labels: %v but got labels: %v", testNum, test.expected, obj.Issue.Labels)
return
}
for i, l := range test.expected {
if l != *obj.Issue.Labels[i].Name {
t.Errorf("%d: expected labels: %v but got labels: %v", testNum, test.expected, obj.Issue.Labels)
}
}
server.Close()
}
}
示例3: TestHasLabels
func TestHasLabels(t *testing.T) {
tests := []struct {
obj MungeObject
seekLabels []string
hasLabel bool
}{
{
obj: MungeObject{
Issue: github_test.Issue("", 1, []string{"foo"}, true),
},
seekLabels: []string{"foo"},
hasLabel: true,
},
{
obj: MungeObject{
Issue: github_test.Issue("", 1, []string{"bar"}, true),
},
seekLabels: []string{"foo"},
hasLabel: false,
},
{
obj: MungeObject{
Issue: github_test.Issue("", 1, []string{"bar", "foo"}, true),
},
seekLabels: []string{"foo"},
hasLabel: true,
},
{
obj: MungeObject{
Issue: github_test.Issue("", 1, []string{"bar", "baz"}, true),
},
seekLabels: []string{"foo"},
hasLabel: false,
},
{
obj: MungeObject{
Issue: github_test.Issue("", 1, []string{"foo"}, true),
},
seekLabels: []string{"foo", "bar"},
hasLabel: false,
},
}
for _, test := range tests {
if test.hasLabel != test.obj.HasLabels(test.seekLabels) {
t.Errorf("Unexpected output: %v", test)
}
}
}
示例4: DoNotMergeMilestoneIssue
func DoNotMergeMilestoneIssue() *github.Issue {
issue := github_test.Issue(someUserName, 1, []string{claYesLabel, lgtmLabel, doNotMergeLabel}, true)
milestone := &github.Milestone{
Title: stringPtr(doNotMergeMilestone),
}
issue.Milestone = milestone
return issue
}
示例5: TestQueueOrder
func TestQueueOrder(t *testing.T) {
timeBase := time.Now()
time2 := timeBase.Add(6 * time.Minute).Unix()
time3 := timeBase.Add(5 * time.Minute).Unix()
time4 := timeBase.Add(4 * time.Minute).Unix()
time5 := timeBase.Add(3 * time.Minute).Unix()
time6 := timeBase.Add(2 * time.Minute).Unix()
labelEvents := map[int][]github_test.LabelTime{
2: {{"me", lgtmLabel, time2}},
3: {{"me", lgtmLabel, time3}},
4: {{"me", lgtmLabel, time4}},
5: {{"me", lgtmLabel, time5}},
6: {{"me", lgtmLabel, time6}},
}
tests := []struct {
name string
issues []*github.Issue
issueToEvents map[int][]github_test.LabelTime
expected []int
}{
{
name: "Just prNum",
issues: []*github.Issue{
github_test.Issue(someUserName, 2, nil, true),
github_test.Issue(someUserName, 3, nil, true),
github_test.Issue(someUserName, 4, nil, true),
github_test.Issue(someUserName, 5, nil, true),
},
issueToEvents: labelEvents,
expected: []int{5, 4, 3, 2},
},
{
name: "With a priority label",
issues: []*github.Issue{
github_test.Issue(someUserName, 2, []string{"priority/P1"}, true),
github_test.Issue(someUserName, 3, []string{"priority/P1"}, true),
github_test.Issue(someUserName, 4, []string{"priority/P0"}, true),
github_test.Issue(someUserName, 5, nil, true),
},
issueToEvents: labelEvents,
expected: []int{4, 3, 2, 5},
},
{
name: "With two priority labels",
issues: []*github.Issue{
github_test.Issue(someUserName, 2, []string{"priority/P1", "priority/P0"}, true),
github_test.Issue(someUserName, 3, []string{"priority/P1"}, true),
github_test.Issue(someUserName, 4, []string{"priority/P0"}, true),
github_test.Issue(someUserName, 5, nil, true),
},
issueToEvents: labelEvents,
expected: []int{4, 2, 3, 5},
},
{
name: "With unrelated labels",
issues: []*github.Issue{
github_test.Issue(someUserName, 2, []string{"priority/P1", "priority/P0"}, true),
github_test.Issue(someUserName, 3, []string{"priority/P1", "kind/design"}, true),
github_test.Issue(someUserName, 4, []string{"priority/P0"}, true),
github_test.Issue(someUserName, 5, []string{lgtmLabel, "kind/new-api"}, true),
},
issueToEvents: labelEvents,
expected: []int{4, 2, 3, 5},
},
{
name: "With invalid priority label",
issues: []*github.Issue{
github_test.Issue(someUserName, 2, []string{"priority/P1", "priority/P0"}, true),
github_test.Issue(someUserName, 3, []string{"priority/P1", "kind/design", "priority/high"}, true),
github_test.Issue(someUserName, 4, []string{"priority/P0", "priorty/bob"}, true),
github_test.Issue(someUserName, 5, nil, true),
},
issueToEvents: labelEvents,
expected: []int{4, 2, 3, 5},
},
{
name: "Unlabeled counts as P3",
issues: []*github.Issue{
github_test.Issue(someUserName, 2, nil, true),
github_test.Issue(someUserName, 3, []string{"priority/P3"}, true),
github_test.Issue(someUserName, 4, []string{"priority/P2"}, true),
github_test.Issue(someUserName, 5, nil, true),
},
issueToEvents: labelEvents,
expected: []int{4, 5, 3, 2},
},
{
name: "retestNotRequiredLabel counts as P-negative 1",
issues: []*github.Issue{
github_test.Issue(someUserName, 2, nil, true),
github_test.Issue(someUserName, 3, []string{"priority/P3"}, true),
github_test.Issue(someUserName, 4, []string{"priority/P0"}, true),
github_test.Issue(someUserName, 5, nil, true),
github_test.Issue(someUserName, 6, []string{"priority/P3", retestNotRequiredLabel}, true),
},
issueToEvents: labelEvents,
expected: []int{6, 4, 5, 3, 2},
},
}
//.........這裏部分代碼省略.........
示例6: NoCLAIssue
func NoCLAIssue() *github.Issue {
return github_test.Issue(someUserName, 1, []string{lgtmLabel}, true)
}
示例7: NoRetestIssue
func NoRetestIssue() *github.Issue {
return github_test.Issue(someUserName, 1, []string{claYesLabel, lgtmLabel, retestNotRequiredLabel}, true)
}
示例8: OnlyApprovedIssue
func OnlyApprovedIssue() *github.Issue {
return github_test.Issue(someUserName, 1, []string{claYesLabel, approvedLabel}, true)
}
示例9: TestAssignFixes
func TestAssignFixes(t *testing.T) {
runtime.GOMAXPROCS(runtime.NumCPU())
tests := []struct {
name string
assignee string
pr *github.PullRequest
prIssue *github.Issue
prBody string
fixesIssue *github.Issue
}{
{
name: "fixes an issue",
assignee: "dev45",
pr: github_test.PullRequest("dev45", false, true, true),
prIssue: github_test.Issue("fred", 7779, []string{}, true),
prBody: "does stuff and fixes #8889.",
fixesIssue: github_test.Issue("jill", 8889, []string{}, true),
},
}
for _, test := range tests {
test.prIssue.Body = &test.prBody
client, server, mux := github_test.InitServer(t, test.prIssue, test.pr, nil, nil, nil, nil)
path := fmt.Sprintf("/repos/o/r/issues/%d", *test.fixesIssue.Number)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
data, err := json.Marshal(test.fixesIssue)
if err != nil {
t.Errorf("%v", err)
}
if r.Method != "PATCH" && r.Method != "GET" {
t.Errorf("Unexpected method: expected: GET/PATCH got: %s", r.Method)
}
if r.Method == "PATCH" {
body, _ := ioutil.ReadAll(r.Body)
type IssuePatch struct {
Assignee string
}
var ip IssuePatch
err := json.Unmarshal(body, &ip)
if err != nil {
fmt.Println("error:", err)
}
if ip.Assignee != test.assignee {
t.Errorf("Patching the incorrect Assignee %v instead of %v", ip.Assignee, test.assignee)
}
}
w.WriteHeader(http.StatusOK)
w.Write(data)
})
config := &github_util.Config{}
config.Org = "o"
config.Project = "r"
config.SetClient(client)
c := AssignFixesMunger{}
err := c.Initialize(config, nil)
if err != nil {
t.Fatalf("%v", err)
}
err = c.EachLoop()
if err != nil {
t.Fatalf("%v", err)
}
obj, err := config.GetObject(*test.prIssue.Number)
if err != nil {
t.Fatalf("%v", err)
}
c.Munge(obj)
server.Close()
}
}
示例10: DoNotMergeIssue
func DoNotMergeIssue() *github.Issue {
return github_test.Issue(someUserName, 1, []string{claYesLabel, lgtmLabel, doNotMergeLabel}, true)
}
示例11: DoNotMergeIssue
func DoNotMergeIssue() *github.Issue {
return github_test.Issue(whitelistUser, 1, []string{"cla: yes", "lgtm", doNotMergeLabel}, true)
}
示例12: TestQueueOrder
func TestQueueOrder(t *testing.T) {
tests := []struct {
name string
issues []github.Issue
expected []int
}{
{
name: "Just prNum",
issues: []github.Issue{
*github_test.Issue(whitelistUser, 2, nil, true),
*github_test.Issue(whitelistUser, 3, nil, true),
*github_test.Issue(whitelistUser, 4, nil, true),
*github_test.Issue(whitelistUser, 5, nil, true),
},
expected: []int{2, 3, 4, 5},
},
{
name: "With a priority label",
issues: []github.Issue{
*github_test.Issue(whitelistUser, 2, []string{"priority/P1"}, true),
*github_test.Issue(whitelistUser, 3, []string{"priority/P1"}, true),
*github_test.Issue(whitelistUser, 4, []string{"priority/P0"}, true),
*github_test.Issue(whitelistUser, 5, nil, true),
},
expected: []int{4, 2, 3, 5},
},
{
name: "With two priority labels",
issues: []github.Issue{
*github_test.Issue(whitelistUser, 2, []string{"priority/P1", "priority/P0"}, true),
*github_test.Issue(whitelistUser, 3, []string{"priority/P1"}, true),
*github_test.Issue(whitelistUser, 4, []string{"priority/P0"}, true),
*github_test.Issue(whitelistUser, 5, nil, true),
},
expected: []int{2, 4, 3, 5},
},
{
name: "With unrelated labels",
issues: []github.Issue{
*github_test.Issue(whitelistUser, 2, []string{"priority/P1", "priority/P0"}, true),
*github_test.Issue(whitelistUser, 3, []string{"priority/P1", "kind/design"}, true),
*github_test.Issue(whitelistUser, 4, []string{"priority/P0"}, true),
*github_test.Issue(whitelistUser, 5, []string{"LGTM", "kind/new-api"}, true),
},
expected: []int{2, 4, 3, 5},
},
{
name: "With invalid priority label",
issues: []github.Issue{
*github_test.Issue(whitelistUser, 2, []string{"priority/P1", "priority/P0"}, true),
*github_test.Issue(whitelistUser, 3, []string{"priority/P1", "kind/design", "priority/high"}, true),
*github_test.Issue(whitelistUser, 4, []string{"priority/P0", "priorty/bob"}, true),
*github_test.Issue(whitelistUser, 5, nil, true),
},
expected: []int{2, 4, 3, 5},
},
{
name: "Unlabeled counts as P3",
issues: []github.Issue{
*github_test.Issue(whitelistUser, 2, nil, true),
*github_test.Issue(whitelistUser, 3, []string{"priority/P3"}, true),
*github_test.Issue(whitelistUser, 4, []string{"priority/P2"}, true),
*github_test.Issue(whitelistUser, 5, nil, true),
},
expected: []int{4, 2, 3, 5},
},
{
name: "e2e-not-required counts as P-negative 1",
issues: []github.Issue{
*github_test.Issue(whitelistUser, 2, nil, true),
*github_test.Issue(whitelistUser, 3, []string{"priority/P3"}, true),
*github_test.Issue(whitelistUser, 4, []string{"priority/P2"}, true),
*github_test.Issue(whitelistUser, 5, nil, true),
*github_test.Issue(whitelistUser, 6, []string{"priority/P3", e2eNotRequiredLabel}, true),
},
expected: []int{6, 4, 2, 3, 5},
},
}
for testNum, test := range tests {
config := &github_util.Config{}
client, server, mux := github_test.InitServer(t, nil, nil, nil, nil, nil)
config.Org = "o"
config.Project = "r"
config.SetClient(client)
sq := getTestSQ(false, config, server)
for i := range test.issues {
issue := &test.issues[i]
github_test.ServeIssue(t, mux, issue)
issueNum := *issue.Number
obj, err := config.GetObject(issueNum)
if err != nil {
t.Fatalf("%d:%q unable to get issue: %v", testNum, test.name, err)
}
sq.githubE2EQueue[issueNum] = obj
}
actual := sq.orderedE2EQueue()
if len(actual) != len(test.expected) {
t.Fatalf("%d:%q len(actual):%v != len(expected):%v", testNum, test.name, actual, test.expected)
}
//.........這裏部分代碼省略.........
示例13: BareIssue
func BareIssue() *github.Issue {
return github_test.Issue(whitelistUser, 1, []string{}, true)
}
示例14: TestForEachIssueDo
func TestForEachIssueDo(t *testing.T) {
issue1 := github_test.Issue("bob", 1, nil, true)
issue5 := github_test.Issue("bob", 5, nil, true)
issue6 := github_test.Issue("bob", 6, nil, true)
issue7 := github_test.Issue("bob", 7, nil, true)
issue20 := github_test.Issue("bob", 20, nil, true)
user := github.User{Login: stringPtr("bob")}
tests := []struct {
Issues [][]github.Issue
Pages []int
ValidIssues int
}{
{
Issues: [][]github.Issue{
{*issue5},
},
Pages: []int{0},
ValidIssues: 1,
},
{
Issues: [][]github.Issue{
{*issue5},
{*issue6},
{*issue7},
{
{
Number: intPtr(8),
// no User, invalid
},
},
},
Pages: []int{4, 4, 4, 0},
ValidIssues: 3,
},
{
Issues: [][]github.Issue{
// Invalid 1 < MinPRNumber
// Invalid 20 > MaxPRNumber
{*issue1, *issue20},
// two valid issues
{*issue5, *issue6},
{
{
// no Number, invalid
User: &user,
},
},
},
Pages: []int{3, 3, 0},
ValidIssues: 2,
},
}
for i, test := range tests {
client, server, mux := github_test.InitServer(t, nil, nil, nil, nil, nil, nil)
config := &Config{
client: client,
Org: "foo",
Project: "bar",
MinPRNumber: 5,
MaxPRNumber: 15,
}
count := 0
mux.HandleFunc("/repos/foo/bar/issues", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
t.Errorf("Unexpected method: %s", r.Method)
}
// this means page 0, return page 1
page := r.URL.Query().Get("page")
if page == "" {
t.Errorf("Should not get page 0, start with page 1")
}
if page != strconv.Itoa(count+1) {
t.Errorf("Unexpected page: %s", r.URL.Query().Get("page"))
}
if r.URL.Query().Get("sort") != "created" {
t.Errorf("Unexpected sort: %s", r.URL.Query().Get("sort"))
}
if r.URL.Query().Get("per_page") != "100" {
t.Errorf("Unexpected per_page: %s", r.URL.Query().Get("per_page"))
}
w.Header().Add("Link",
fmt.Sprintf("<https://api.github.com/?page=%d>; rel=\"last\"", test.Pages[count]))
w.WriteHeader(http.StatusOK)
data, err := json.Marshal(test.Issues[count])
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
w.Write(data)
count++
})
objects := []*MungeObject{}
handle := func(obj *MungeObject) error {
objects = append(objects, obj)
return nil
}
err := config.ForEachIssueDo(handle)
if err != nil {
//.........這裏部分代碼省略.........
示例15: TestGetLastModified
func TestGetLastModified(t *testing.T) {
tests := []struct {
commits []github.RepositoryCommit
expectedTime *time.Time
}{
{
commits: github_test.Commits(1, 10),
expectedTime: timePtr(time.Unix(10, 0)),
},
{
// remember the order of github_test.Commits() is non-deterministic
commits: github_test.Commits(3, 10),
expectedTime: timePtr(time.Unix(12, 0)),
},
{
// so this is probably not quite the same test...
commits: github_test.Commits(3, 8),
expectedTime: timePtr(time.Unix(10, 0)),
},
{
// We can't represent the same time in 2 commits using github_test.Commits()
commits: []github.RepositoryCommit{
{
SHA: stringPtr("mysha1"),
Commit: &github.Commit{
SHA: stringPtr("mysha1"),
Committer: &github.CommitAuthor{
Date: timePtr(time.Unix(9, 0)),
},
},
},
{
SHA: stringPtr("mysha2"),
Commit: &github.Commit{
SHA: stringPtr("mysha2"),
Committer: &github.CommitAuthor{
Date: timePtr(time.Unix(10, 0)),
},
},
},
{
SHA: stringPtr("mysha3"),
Commit: &github.Commit{
SHA: stringPtr("mysha3"),
Committer: &github.CommitAuthor{
Date: timePtr(time.Unix(9, 0)),
},
},
},
},
expectedTime: timePtr(time.Unix(10, 0)),
},
}
for _, test := range tests {
client, server, _ := github_test.InitServer(t, nil, nil, nil, test.commits, nil, nil)
config := &Config{}
config.Org = "o"
config.Project = "r"
config.SetClient(client)
obj := &MungeObject{
config: config,
Issue: github_test.Issue("bob", 1, nil, true),
}
ts := obj.LastModifiedTime()
if !ts.Equal(*test.expectedTime) {
t.Errorf("expected: %v, saw: %v for: %v", test.expectedTime, ts, test)
}
server.Close()
}
}