|
4 | 4 | "fmt"
|
5 | 5 | "net/http"
|
6 | 6 | "net/http/httptest"
|
| 7 | + "testing" |
7 | 8 |
|
8 | 9 | "github.com/andygrunwald/go-gerrit"
|
9 | 10 | )
|
@@ -77,3 +78,193 @@ func ExampleChangesService_PublishChangeEdit() {
|
77 | 78 | panic(err)
|
78 | 79 | }
|
79 | 80 | }
|
| 81 | + |
| 82 | +func TestChangesService_SubmitChange(t *testing.T) { |
| 83 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 84 | + if r.URL.Path != "/changes/123/submit" { |
| 85 | + t.Errorf("%s != /changes/123/submit", r.URL.Path) |
| 86 | + } |
| 87 | + fmt.Fprint(w, `{"id": "123"}`) |
| 88 | + })) |
| 89 | + defer ts.Close() |
| 90 | + |
| 91 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 92 | + if err != nil { |
| 93 | + t.Error(err) |
| 94 | + } |
| 95 | + info, _, err := client.Changes.SubmitChange("123", nil) |
| 96 | + if err != nil { |
| 97 | + t.Error(err) |
| 98 | + } |
| 99 | + if info.ID != "123" { |
| 100 | + t.Error("Invalid id") |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +func TestChangesService_SubmitChange_Conflict(t *testing.T) { |
| 105 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 106 | + w.WriteHeader(http.StatusConflict) |
| 107 | + })) |
| 108 | + defer ts.Close() |
| 109 | + |
| 110 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 111 | + if err != nil { |
| 112 | + t.Error(err) |
| 113 | + } |
| 114 | + _, response, _ := client.Changes.SubmitChange("123", nil) |
| 115 | + if response.StatusCode != http.StatusConflict { |
| 116 | + t.Error("Expected 409 code") |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +func TestChangesService_AbandonChange(t *testing.T) { |
| 121 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 122 | + if r.URL.Path != "/changes/123/abandon" { |
| 123 | + t.Errorf("%s != /changes/123/abandon", r.URL.Path) |
| 124 | + } |
| 125 | + fmt.Fprint(w, `{"id": "123"}`) |
| 126 | + })) |
| 127 | + defer ts.Close() |
| 128 | + |
| 129 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 130 | + if err != nil { |
| 131 | + t.Error(err) |
| 132 | + } |
| 133 | + info, _, err := client.Changes.AbandonChange("123", nil) |
| 134 | + if err != nil { |
| 135 | + t.Error(err) |
| 136 | + } |
| 137 | + if info.ID != "123" { |
| 138 | + t.Error("Invalid id") |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +func TestChangesService_AbandonChange_Conflict(t *testing.T) { |
| 143 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 144 | + w.WriteHeader(http.StatusConflict) |
| 145 | + })) |
| 146 | + defer ts.Close() |
| 147 | + |
| 148 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 149 | + if err != nil { |
| 150 | + t.Error(err) |
| 151 | + } |
| 152 | + _, response, _ := client.Changes.AbandonChange("123", nil) |
| 153 | + if response.StatusCode != http.StatusConflict { |
| 154 | + t.Error("Expected 409 code") |
| 155 | + } |
| 156 | +} |
| 157 | + |
| 158 | +func TestChangesService_RebaseChange(t *testing.T) { |
| 159 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 160 | + if r.URL.Path != "/changes/123/rebase" { |
| 161 | + t.Errorf("%s != /changes/123/rebase", r.URL.Path) |
| 162 | + } |
| 163 | + fmt.Fprint(w, `{"id": "123"}`) |
| 164 | + })) |
| 165 | + defer ts.Close() |
| 166 | + |
| 167 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 168 | + if err != nil { |
| 169 | + t.Error(err) |
| 170 | + } |
| 171 | + info, _, err := client.Changes.RebaseChange("123", nil) |
| 172 | + if err != nil { |
| 173 | + t.Error(err) |
| 174 | + } |
| 175 | + if info.ID != "123" { |
| 176 | + t.Error("Invalid id") |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +func TestChangesService_RebaseChange_Conflict(t *testing.T) { |
| 181 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 182 | + w.WriteHeader(http.StatusConflict) |
| 183 | + })) |
| 184 | + defer ts.Close() |
| 185 | + |
| 186 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 187 | + if err != nil { |
| 188 | + t.Error(err) |
| 189 | + } |
| 190 | + _, response, _ := client.Changes.RebaseChange("123", nil) |
| 191 | + if response.StatusCode != http.StatusConflict { |
| 192 | + t.Error("Expected 409 code") |
| 193 | + } |
| 194 | +} |
| 195 | + |
| 196 | +func TestChangesService_RestoreChange(t *testing.T) { |
| 197 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 198 | + if r.URL.Path != "/changes/123/restore" { |
| 199 | + t.Errorf("%s != /changes/123/restore", r.URL.Path) |
| 200 | + } |
| 201 | + fmt.Fprint(w, `{"id": "123"}`) |
| 202 | + })) |
| 203 | + defer ts.Close() |
| 204 | + |
| 205 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 206 | + if err != nil { |
| 207 | + t.Error(err) |
| 208 | + } |
| 209 | + info, _, err := client.Changes.RestoreChange("123", nil) |
| 210 | + if err != nil { |
| 211 | + t.Error(err) |
| 212 | + } |
| 213 | + if info.ID != "123" { |
| 214 | + t.Error("Invalid id") |
| 215 | + } |
| 216 | +} |
| 217 | + |
| 218 | +func TestChangesService_RestoreChange_Conflict(t *testing.T) { |
| 219 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 220 | + w.WriteHeader(http.StatusConflict) |
| 221 | + })) |
| 222 | + defer ts.Close() |
| 223 | + |
| 224 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 225 | + if err != nil { |
| 226 | + t.Error(err) |
| 227 | + } |
| 228 | + _, response, _ := client.Changes.RestoreChange("123", nil) |
| 229 | + if response.StatusCode != http.StatusConflict { |
| 230 | + t.Error("Expected 409 code") |
| 231 | + } |
| 232 | +} |
| 233 | + |
| 234 | +func TestChangesService_RevertChange(t *testing.T) { |
| 235 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 236 | + if r.URL.Path != "/changes/123/revert" { |
| 237 | + t.Errorf("%s != /changes/123/revert", r.URL.Path) |
| 238 | + } |
| 239 | + fmt.Fprint(w, `{"id": "123"}`) |
| 240 | + })) |
| 241 | + defer ts.Close() |
| 242 | + |
| 243 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 244 | + if err != nil { |
| 245 | + t.Error(err) |
| 246 | + } |
| 247 | + info, _, err := client.Changes.RevertChange("123", nil) |
| 248 | + if err != nil { |
| 249 | + t.Error(err) |
| 250 | + } |
| 251 | + if info.ID != "123" { |
| 252 | + t.Error("Invalid id") |
| 253 | + } |
| 254 | +} |
| 255 | + |
| 256 | +func TestChangesService_RevertChange_Conflict(t *testing.T) { |
| 257 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 258 | + w.WriteHeader(http.StatusConflict) |
| 259 | + })) |
| 260 | + defer ts.Close() |
| 261 | + |
| 262 | + client, err := gerrit.NewClient(ts.URL, nil) |
| 263 | + if err != nil { |
| 264 | + t.Error(err) |
| 265 | + } |
| 266 | + _, response, _ := client.Changes.RevertChange("123", nil) |
| 267 | + if response.StatusCode != http.StatusConflict { |
| 268 | + t.Error("Expected 409 code") |
| 269 | + } |
| 270 | +} |
0 commit comments