@@ -45,7 +45,6 @@ func TestIssueImportService_Create(t *testing.T) {
45
45
t .Errorf ("Request body = %+v, want %+v" , v , input )
46
46
}
47
47
48
- w .WriteHeader (http .StatusAccepted )
49
48
w .Write (issueImportResponseJSON )
50
49
})
51
50
@@ -75,6 +74,93 @@ func TestIssueImportService_Create(t *testing.T) {
75
74
})
76
75
}
77
76
77
+ func TestIssueImportService_Create_defered (t * testing.T ) {
78
+ client , mux , _ , teardown := setup ()
79
+ defer teardown ()
80
+
81
+ createdAt := time .Date (2020 , time .August , 11 , 15 , 30 , 0 , 0 , time .UTC )
82
+ input := & IssueImportRequest {
83
+ IssueImport : IssueImport {
84
+ Assignee : String ("developer" ),
85
+ Body : "Dummy description" ,
86
+ CreatedAt : & Timestamp {createdAt },
87
+ Labels : []string {"l1" , "l2" },
88
+ Milestone : Int (1 ),
89
+ Title : "Dummy Issue" ,
90
+ },
91
+ Comments : []* Comment {{
92
+ CreatedAt : & Timestamp {createdAt },
93
+ Body : "Comment body" ,
94
+ }},
95
+ }
96
+
97
+ mux .HandleFunc ("/repos/o/r/import/issues" , func (w http.ResponseWriter , r * http.Request ) {
98
+ v := new (IssueImportRequest )
99
+ json .NewDecoder (r .Body ).Decode (v )
100
+ testMethod (t , r , "POST" )
101
+ testHeader (t , r , "Accept" , mediaTypeIssueImportAPI )
102
+ if ! cmp .Equal (v , input ) {
103
+ t .Errorf ("Request body = %+v, want %+v" , v , input )
104
+ }
105
+
106
+ w .WriteHeader (http .StatusAccepted )
107
+ w .Write (issueImportResponseJSON )
108
+ })
109
+
110
+ ctx := context .Background ()
111
+ got , _ , err := client .IssueImport .Create (ctx , "o" , "r" , input )
112
+
113
+ if _ , ok := err .(* AcceptedError ); ! ok {
114
+ t .Errorf ("Create returned error: %v (want AcceptedError)" , err )
115
+ }
116
+
117
+ want := wantIssueImportResponse
118
+ if ! cmp .Equal (got , want ) {
119
+ t .Errorf ("Create = %+v, want %+v" , got , want )
120
+ }
121
+ }
122
+
123
+ func TestIssueImportService_Create_badResponse (t * testing.T ) {
124
+ client , mux , _ , teardown := setup ()
125
+ defer teardown ()
126
+
127
+ createdAt := time .Date (2020 , time .August , 11 , 15 , 30 , 0 , 0 , time .UTC )
128
+ input := & IssueImportRequest {
129
+ IssueImport : IssueImport {
130
+ Assignee : String ("developer" ),
131
+ Body : "Dummy description" ,
132
+ CreatedAt : & Timestamp {createdAt },
133
+ Labels : []string {"l1" , "l2" },
134
+ Milestone : Int (1 ),
135
+ Title : "Dummy Issue" ,
136
+ },
137
+ Comments : []* Comment {{
138
+ CreatedAt : & Timestamp {createdAt },
139
+ Body : "Comment body" ,
140
+ }},
141
+ }
142
+
143
+ mux .HandleFunc ("/repos/o/r/import/issues" , func (w http.ResponseWriter , r * http.Request ) {
144
+ v := new (IssueImportRequest )
145
+ json .NewDecoder (r .Body ).Decode (v )
146
+ testMethod (t , r , "POST" )
147
+ testHeader (t , r , "Accept" , mediaTypeIssueImportAPI )
148
+ if ! cmp .Equal (v , input ) {
149
+ t .Errorf ("Request body = %+v, want %+v" , v , input )
150
+ }
151
+
152
+ w .WriteHeader (http .StatusAccepted )
153
+ w .Write ([]byte ("{[}" ))
154
+ })
155
+
156
+ ctx := context .Background ()
157
+ _ , _ , err := client .IssueImport .Create (ctx , "o" , "r" , input )
158
+
159
+ if err == nil || err .Error () != "invalid character '[' looking for beginning of object key string" {
160
+ t .Errorf ("unexpected error: %v" , err )
161
+ }
162
+ }
163
+
78
164
func TestIssueImportService_Create_invalidOwner (t * testing.T ) {
79
165
client , _ , _ , teardown := setup ()
80
166
defer teardown ()
0 commit comments