forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue_import_test.go
More file actions
144 lines (120 loc) · 4.04 KB
/
issue_import_test.go
File metadata and controls
144 lines (120 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2020 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
"time"
)
func TestIssueImportService_Create(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
createdAt := time.Date(2020, time.August, 11, 15, 30, 0, 0, time.UTC)
input := &IssueImportRequest{
IssueImport: IssueImport{
Assignee: String("developer"),
Body: "Dummy description",
CreatedAt: &createdAt,
Labels: []string{"l1", "l2"},
Milestone: Int(1),
Title: "Dummy Issue",
},
Comments: []*Comment{{
CreatedAt: &createdAt,
Body: "Comment body",
}},
}
mux.HandleFunc("/repos/o/r/import/issues", func(w http.ResponseWriter, r *http.Request) {
v := new(IssueImportRequest)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeIssueImportAPI)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
w.WriteHeader(http.StatusAccepted)
w.Write(issueImportResponseJSON)
})
got, _, err := client.IssueImport.Create(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Create returned error: %v", err)
}
want := wantIssueImportResponse
if !reflect.DeepEqual(got, want) {
t.Errorf("Create = %+v, want %+v", got, want)
}
}
func TestIssueImportService_Create_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.IssueImport.Create(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
func TestIssueImportService_CheckStatus(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/import/issues/3", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeIssueImportAPI)
w.WriteHeader(http.StatusOK)
w.Write(issueImportResponseJSON)
})
got, _, err := client.IssueImport.CheckStatus(context.Background(), "o", "r", 3)
if err != nil {
t.Errorf("CheckStatus returned error: %v", err)
}
want := wantIssueImportResponse
if !reflect.DeepEqual(got, want) {
t.Errorf("CheckStatus = %+v, want %+v", got, want)
}
}
func TestIssueImportService_CheckStatus_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.IssueImport.CheckStatus(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
func TestIssueImportService_CheckStatusSince(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/import/issues", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeIssueImportAPI)
w.WriteHeader(http.StatusOK)
w.Write([]byte(fmt.Sprintf("[%s]", issueImportResponseJSON)))
})
got, _, err := client.IssueImport.CheckStatusSince(context.Background(), "o", "r", time.Now())
if err != nil {
t.Errorf("CheckStatusSince returned error: %v", err)
}
want := []*IssueImportResponse{wantIssueImportResponse}
if !reflect.DeepEqual(want, got) {
t.Errorf("CheckStatusSince = %v, want = %v", got, want)
}
}
func TestIssueImportService_CheckStatusSince_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
_, _, err := client.IssueImport.CheckStatusSince(context.Background(), "%", "r", time.Now())
testURLParseError(t, err)
}
var issueImportResponseJSON = []byte(`{
"id": 3,
"status": "pending",
"url": "https://api.github.com/repos/o/r/import/issues/3",
"import_issues_url": "https://api.github.com/repos/o/r/import/issues",
"repository_url": "https://api.github.com/repos/o/r"
}`)
var wantIssueImportResponse = &IssueImportResponse{
ID: Int(3),
Status: String("pending"),
URL: String("https://api.github.com/repos/o/r/import/issues/3"),
ImportIssuesURL: String("https://api.github.com/repos/o/r/import/issues"),
RepositoryURL: String("https://api.github.com/repos/o/r"),
}