| 1 |
// Copyright 2014 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"bytes" |
| 10 |
"context" |
| 11 |
"encoding/json" |
| 12 |
"fmt" |
| 13 |
"io" |
| 14 |
"net/http" |
| 15 |
"testing" |
| 16 |
|
| 17 |
"github.com/google/go-cmp/cmp" |
| 18 |
) |
| 19 |
|
| 20 |
func TestRepositoriesService_EnablePagesLegacy(t *testing.T) { |
| 21 |
client, mux, _, teardown := setup() |
| 22 |
defer teardown() |
| 23 |
|
| 24 |
input := &Pages{ |
| 25 |
BuildType: String("legacy"), |
| 26 |
Source: &PagesSource{ |
| 27 |
Branch: String("master"), |
| 28 |
Path: String("/"), |
| 29 |
}, |
| 30 |
CNAME: String("www.my-domain.com"), // not passed along. |
| 31 |
} |
| 32 |
|
| 33 |
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { |
| 34 |
v := new(createPagesRequest) |
| 35 |
assertNilError(t, json.NewDecoder(r.Body).Decode(v)) |
| 36 |
|
| 37 |
testMethod(t, r, "POST") |
| 38 |
testHeader(t, r, "Accept", mediaTypeEnablePagesAPIPreview) |
| 39 |
want := &createPagesRequest{BuildType: String("legacy"), Source: &PagesSource{Branch: String("master"), Path: String("/")}} |
| 40 |
if !cmp.Equal(v, want) { |
| 41 |
t.Errorf("Request body = %+v, want %+v", v, want) |
| 42 |
} |
| 43 |
|
| 44 |
fmt.Fprint(w, `{"url":"u","status":"s","cname":"c","custom_404":false,"html_url":"h","build_type": "legacy","source": {"branch":"master", "path":"/"}}`) |
| 45 |
}) |
| 46 |
|
| 47 |
ctx := context.Background() |
| 48 |
page, _, err := client.Repositories.EnablePages(ctx, "o", "r", input) |
| 49 |
if err != nil { |
| 50 |
t.Errorf("Repositories.EnablePages returned error: %v", err) |
| 51 |
} |
| 52 |
|
| 53 |
want := &Pages{URL: String("u"), Status: String("s"), CNAME: String("c"), Custom404: Bool(false), HTMLURL: String("h"), BuildType: String("legacy"), Source: &PagesSource{Branch: String("master"), Path: String("/")}} |
| 54 |
|
| 55 |
if !cmp.Equal(page, want) { |
| 56 |
t.Errorf("Repositories.EnablePages returned %v, want %v", page, want) |
| 57 |
} |
| 58 |
|
| 59 |
const methodName = "EnablePages" |
| 60 |
testBadOptions(t, methodName, func() (err error) { |
| 61 |
_, _, err = client.Repositories.EnablePages(ctx, "\n", "\n", input) |
| 62 |
return err |
| 63 |
}) |
| 64 |
|
| 65 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 66 |
got, resp, err := client.Repositories.EnablePages(ctx, "o", "r", input) |
| 67 |
if got != nil { |
| 68 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 69 |
} |
| 70 |
return resp, err |
| 71 |
}) |
| 72 |
} |
| 73 |
|
| 74 |
func TestRepositoriesService_EnablePagesWorkflow(t *testing.T) { |
| 75 |
client, mux, _, teardown := setup() |
| 76 |
defer teardown() |
| 77 |
|
| 78 |
input := &Pages{ |
| 79 |
BuildType: String("workflow"), |
| 80 |
CNAME: String("www.my-domain.com"), // not passed along. |
| 81 |
} |
| 82 |
|
| 83 |
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { |
| 84 |
v := new(createPagesRequest) |
| 85 |
assertNilError(t, json.NewDecoder(r.Body).Decode(v)) |
| 86 |
|
| 87 |
testMethod(t, r, "POST") |
| 88 |
testHeader(t, r, "Accept", mediaTypeEnablePagesAPIPreview) |
| 89 |
want := &createPagesRequest{BuildType: String("workflow")} |
| 90 |
if !cmp.Equal(v, want) { |
| 91 |
t.Errorf("Request body = %+v, want %+v", v, want) |
| 92 |
} |
| 93 |
|
| 94 |
fmt.Fprint(w, `{"url":"u","status":"s","cname":"c","custom_404":false,"html_url":"h","build_type": "workflow"}`) |
| 95 |
}) |
| 96 |
|
| 97 |
ctx := context.Background() |
| 98 |
page, _, err := client.Repositories.EnablePages(ctx, "o", "r", input) |
| 99 |
if err != nil { |
| 100 |
t.Errorf("Repositories.EnablePages returned error: %v", err) |
| 101 |
} |
| 102 |
|
| 103 |
want := &Pages{URL: String("u"), Status: String("s"), CNAME: String("c"), Custom404: Bool(false), HTMLURL: String("h"), BuildType: String("workflow")} |
| 104 |
|
| 105 |
if !cmp.Equal(page, want) { |
| 106 |
t.Errorf("Repositories.EnablePages returned %v, want %v", page, want) |
| 107 |
} |
| 108 |
|
| 109 |
const methodName = "EnablePages" |
| 110 |
testBadOptions(t, methodName, func() (err error) { |
| 111 |
_, _, err = client.Repositories.EnablePages(ctx, "\n", "\n", input) |
| 112 |
return err |
| 113 |
}) |
| 114 |
|
| 115 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 116 |
got, resp, err := client.Repositories.EnablePages(ctx, "o", "r", input) |
| 117 |
if got != nil { |
| 118 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 119 |
} |
| 120 |
return resp, err |
| 121 |
}) |
| 122 |
} |
| 123 |
|
| 124 |
func TestRepositoriesService_UpdatePagesLegacy(t *testing.T) { |
| 125 |
client, mux, _, teardown := setup() |
| 126 |
defer teardown() |
| 127 |
|
| 128 |
input := &PagesUpdate{ |
| 129 |
CNAME: String("www.my-domain.com"), |
| 130 |
BuildType: String("legacy"), |
| 131 |
Source: &PagesSource{Branch: String("gh-pages")}, |
| 132 |
} |
| 133 |
|
| 134 |
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { |
| 135 |
v := new(PagesUpdate) |
| 136 |
assertNilError(t, json.NewDecoder(r.Body).Decode(v)) |
| 137 |
|
| 138 |
testMethod(t, r, "PUT") |
| 139 |
want := &PagesUpdate{CNAME: String("www.my-domain.com"), BuildType: String("legacy"), Source: &PagesSource{Branch: String("gh-pages")}} |
| 140 |
if !cmp.Equal(v, want) { |
| 141 |
t.Errorf("Request body = %+v, want %+v", v, want) |
| 142 |
} |
| 143 |
|
| 144 |
fmt.Fprint(w, `{"cname":"www.my-domain.com","build_type":"legacy","source":{"branch":"gh-pages"}}`) |
| 145 |
}) |
| 146 |
|
| 147 |
ctx := context.Background() |
| 148 |
_, err := client.Repositories.UpdatePages(ctx, "o", "r", input) |
| 149 |
if err != nil { |
| 150 |
t.Errorf("Repositories.UpdatePages returned error: %v", err) |
| 151 |
} |
| 152 |
|
| 153 |
const methodName = "UpdatePages" |
| 154 |
testBadOptions(t, methodName, func() (err error) { |
| 155 |
_, err = client.Repositories.UpdatePages(ctx, "\n", "\n", input) |
| 156 |
return err |
| 157 |
}) |
| 158 |
|
| 159 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 160 |
return client.Repositories.UpdatePages(ctx, "o", "r", input) |
| 161 |
}) |
| 162 |
} |
| 163 |
|
| 164 |
func TestRepositoriesService_UpdatePagesWorkflow(t *testing.T) { |
| 165 |
client, mux, _, teardown := setup() |
| 166 |
defer teardown() |
| 167 |
|
| 168 |
input := &PagesUpdate{ |
| 169 |
CNAME: String("www.my-domain.com"), |
| 170 |
BuildType: String("workflow"), |
| 171 |
} |
| 172 |
|
| 173 |
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { |
| 174 |
v := new(PagesUpdate) |
| 175 |
assertNilError(t, json.NewDecoder(r.Body).Decode(v)) |
| 176 |
|
| 177 |
testMethod(t, r, "PUT") |
| 178 |
want := &PagesUpdate{CNAME: String("www.my-domain.com"), BuildType: String("workflow")} |
| 179 |
if !cmp.Equal(v, want) { |
| 180 |
t.Errorf("Request body = %+v, want %+v", v, want) |
| 181 |
} |
| 182 |
|
| 183 |
fmt.Fprint(w, `{"cname":"www.my-domain.com","build_type":"workflow"}`) |
| 184 |
}) |
| 185 |
|
| 186 |
ctx := context.Background() |
| 187 |
_, err := client.Repositories.UpdatePages(ctx, "o", "r", input) |
| 188 |
if err != nil { |
| 189 |
t.Errorf("Repositories.UpdatePages returned error: %v", err) |
| 190 |
} |
| 191 |
|
| 192 |
const methodName = "UpdatePages" |
| 193 |
testBadOptions(t, methodName, func() (err error) { |
| 194 |
_, err = client.Repositories.UpdatePages(ctx, "\n", "\n", input) |
| 195 |
return err |
| 196 |
}) |
| 197 |
|
| 198 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 199 |
return client.Repositories.UpdatePages(ctx, "o", "r", input) |
| 200 |
}) |
| 201 |
} |
| 202 |
|
| 203 |
func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) { |
| 204 |
client, mux, _, teardown := setup() |
| 205 |
defer teardown() |
| 206 |
|
| 207 |
input := &PagesUpdate{ |
| 208 |
Source: &PagesSource{Branch: String("gh-pages")}, |
| 209 |
} |
| 210 |
|
| 211 |
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { |
| 212 |
got, err := io.ReadAll(r.Body) |
| 213 |
if err != nil { |
| 214 |
t.Fatalf("unable to read body: %v", err) |
| 215 |
} |
| 216 |
|
| 217 |
want := []byte(`{"cname":null,"source":{"branch":"gh-pages"}}` + "\n") |
| 218 |
if !bytes.Equal(got, want) { |
| 219 |
t.Errorf("Request body = %+v, want %+v", got, want) |
| 220 |
} |
| 221 |
|
| 222 |
fmt.Fprint(w, `{"cname":null,"source":{"branch":"gh-pages"}}`) |
| 223 |
}) |
| 224 |
|
| 225 |
ctx := context.Background() |
| 226 |
_, err := client.Repositories.UpdatePages(ctx, "o", "r", input) |
| 227 |
if err != nil { |
| 228 |
t.Errorf("Repositories.UpdatePages returned error: %v", err) |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
func TestRepositoriesService_DisablePages(t *testing.T) { |
| 233 |
client, mux, _, teardown := setup() |
| 234 |
defer teardown() |
| 235 |
|
| 236 |
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { |
| 237 |
testMethod(t, r, "DELETE") |
| 238 |
testHeader(t, r, "Accept", mediaTypeEnablePagesAPIPreview) |
| 239 |
}) |
| 240 |
|
| 241 |
ctx := context.Background() |
| 242 |
_, err := client.Repositories.DisablePages(ctx, "o", "r") |
| 243 |
if err != nil { |
| 244 |
t.Errorf("Repositories.DisablePages returned error: %v", err) |
| 245 |
} |
| 246 |
|
| 247 |
const methodName = "DisablePages" |
| 248 |
testBadOptions(t, methodName, func() (err error) { |
| 249 |
_, err = client.Repositories.DisablePages(ctx, "\n", "\n") |
| 250 |
return err |
| 251 |
}) |
| 252 |
|
| 253 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 254 |
return client.Repositories.DisablePages(ctx, "o", "r") |
| 255 |
}) |
| 256 |
} |
| 257 |
|
| 258 |
func TestRepositoriesService_GetPagesInfo(t *testing.T) { |
| 259 |
client, mux, _, teardown := setup() |
| 260 |
defer teardown() |
| 261 |
|
| 262 |
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { |
| 263 |
testMethod(t, r, "GET") |
| 264 |
fmt.Fprint(w, `{"url":"u","status":"s","cname":"c","custom_404":false,"html_url":"h","public":true, "https_certificate": {"state":"approved","description": "Certificate is approved","domains": ["developer.github.com"],"expires_at": "2021-05-22"},"https_enforced": true}`) |
| 265 |
}) |
| 266 |
|
| 267 |
ctx := context.Background() |
| 268 |
page, _, err := client.Repositories.GetPagesInfo(ctx, "o", "r") |
| 269 |
if err != nil { |
| 270 |
t.Errorf("Repositories.GetPagesInfo returned error: %v", err) |
| 271 |
} |
| 272 |
|
| 273 |
want := &Pages{URL: String("u"), Status: String("s"), CNAME: String("c"), Custom404: Bool(false), HTMLURL: String("h"), Public: Bool(true), HTTPSCertificate: &PagesHTTPSCertificate{State: String("approved"), Description: String("Certificate is approved"), Domains: []string{"developer.github.com"}, ExpiresAt: String("2021-05-22")}, HTTPSEnforced: Bool(true)} |
| 274 |
if !cmp.Equal(page, want) { |
| 275 |
t.Errorf("Repositories.GetPagesInfo returned %+v, want %+v", page, want) |
| 276 |
} |
| 277 |
|
| 278 |
const methodName = "GetPagesInfo" |
| 279 |
testBadOptions(t, methodName, func() (err error) { |
| 280 |
_, _, err = client.Repositories.GetPagesInfo(ctx, "\n", "\n") |
| 281 |
return err |
| 282 |
}) |
| 283 |
|
| 284 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 285 |
got, resp, err := client.Repositories.GetPagesInfo(ctx, "o", "r") |
| 286 |
if got != nil { |
| 287 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 288 |
} |
| 289 |
return resp, err |
| 290 |
}) |
| 291 |
} |
| 292 |
|
| 293 |
func TestRepositoriesService_ListPagesBuilds(t *testing.T) { |
| 294 |
client, mux, _, teardown := setup() |
| 295 |
defer teardown() |
| 296 |
|
| 297 |
mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { |
| 298 |
testMethod(t, r, "GET") |
| 299 |
fmt.Fprint(w, `[{"url":"u","status":"s","commit":"c"}]`) |
| 300 |
}) |
| 301 |
|
| 302 |
ctx := context.Background() |
| 303 |
pages, _, err := client.Repositories.ListPagesBuilds(ctx, "o", "r", nil) |
| 304 |
if err != nil { |
| 305 |
t.Errorf("Repositories.ListPagesBuilds returned error: %v", err) |
| 306 |
} |
| 307 |
|
| 308 |
want := []*PagesBuild{{URL: String("u"), Status: String("s"), Commit: String("c")}} |
| 309 |
if !cmp.Equal(pages, want) { |
| 310 |
t.Errorf("Repositories.ListPagesBuilds returned %+v, want %+v", pages, want) |
| 311 |
} |
| 312 |
|
| 313 |
const methodName = "ListPagesBuilds" |
| 314 |
testBadOptions(t, methodName, func() (err error) { |
| 315 |
_, _, err = client.Repositories.ListPagesBuilds(ctx, "\n", "\n", nil) |
| 316 |
return err |
| 317 |
}) |
| 318 |
|
| 319 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 320 |
got, resp, err := client.Repositories.ListPagesBuilds(ctx, "o", "r", nil) |
| 321 |
if got != nil { |
| 322 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 323 |
} |
| 324 |
return resp, err |
| 325 |
}) |
| 326 |
} |
| 327 |
|
| 328 |
func TestRepositoriesService_ListPagesBuilds_withOptions(t *testing.T) { |
| 329 |
client, mux, _, teardown := setup() |
| 330 |
defer teardown() |
| 331 |
|
| 332 |
mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { |
| 333 |
testMethod(t, r, "GET") |
| 334 |
testFormValues(t, r, values{ |
| 335 |
"page": "2", |
| 336 |
}) |
| 337 |
fmt.Fprint(w, `[]`) |
| 338 |
}) |
| 339 |
|
| 340 |
ctx := context.Background() |
| 341 |
_, _, err := client.Repositories.ListPagesBuilds(ctx, "o", "r", &ListOptions{Page: 2}) |
| 342 |
if err != nil { |
| 343 |
t.Errorf("Repositories.ListPagesBuilds returned error: %v", err) |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
func TestRepositoriesService_GetLatestPagesBuild(t *testing.T) { |
| 348 |
client, mux, _, teardown := setup() |
| 349 |
defer teardown() |
| 350 |
|
| 351 |
mux.HandleFunc("/repos/o/r/pages/builds/latest", func(w http.ResponseWriter, r *http.Request) { |
| 352 |
testMethod(t, r, "GET") |
| 353 |
fmt.Fprint(w, `{"url":"u","status":"s","commit":"c"}`) |
| 354 |
}) |
| 355 |
|
| 356 |
ctx := context.Background() |
| 357 |
build, _, err := client.Repositories.GetLatestPagesBuild(ctx, "o", "r") |
| 358 |
if err != nil { |
| 359 |
t.Errorf("Repositories.GetLatestPagesBuild returned error: %v", err) |
| 360 |
} |
| 361 |
|
| 362 |
want := &PagesBuild{URL: String("u"), Status: String("s"), Commit: String("c")} |
| 363 |
if !cmp.Equal(build, want) { |
| 364 |
t.Errorf("Repositories.GetLatestPagesBuild returned %+v, want %+v", build, want) |
| 365 |
} |
| 366 |
|
| 367 |
const methodName = "GetLatestPagesBuild" |
| 368 |
testBadOptions(t, methodName, func() (err error) { |
| 369 |
_, _, err = client.Repositories.GetLatestPagesBuild(ctx, "\n", "\n") |
| 370 |
return err |
| 371 |
}) |
| 372 |
|
| 373 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 374 |
got, resp, err := client.Repositories.GetLatestPagesBuild(ctx, "o", "r") |
| 375 |
if got != nil { |
| 376 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 377 |
} |
| 378 |
return resp, err |
| 379 |
}) |
| 380 |
} |
| 381 |
|
| 382 |
func TestRepositoriesService_GetPageBuild(t *testing.T) { |
| 383 |
client, mux, _, teardown := setup() |
| 384 |
defer teardown() |
| 385 |
|
| 386 |
mux.HandleFunc("/repos/o/r/pages/builds/1", func(w http.ResponseWriter, r *http.Request) { |
| 387 |
testMethod(t, r, "GET") |
| 388 |
fmt.Fprint(w, `{"url":"u","status":"s","commit":"c"}`) |
| 389 |
}) |
| 390 |
|
| 391 |
ctx := context.Background() |
| 392 |
build, _, err := client.Repositories.GetPageBuild(ctx, "o", "r", 1) |
| 393 |
if err != nil { |
| 394 |
t.Errorf("Repositories.GetPageBuild returned error: %v", err) |
| 395 |
} |
| 396 |
|
| 397 |
want := &PagesBuild{URL: String("u"), Status: String("s"), Commit: String("c")} |
| 398 |
if !cmp.Equal(build, want) { |
| 399 |
t.Errorf("Repositories.GetPageBuild returned %+v, want %+v", build, want) |
| 400 |
} |
| 401 |
|
| 402 |
const methodName = "GetPageBuild" |
| 403 |
testBadOptions(t, methodName, func() (err error) { |
| 404 |
_, _, err = client.Repositories.GetPageBuild(ctx, "\n", "\n", -1) |
| 405 |
return err |
| 406 |
}) |
| 407 |
|
| 408 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 409 |
got, resp, err := client.Repositories.GetPageBuild(ctx, "o", "r", 1) |
| 410 |
if got != nil { |
| 411 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 412 |
} |
| 413 |
return resp, err |
| 414 |
}) |
| 415 |
} |
| 416 |
|
| 417 |
func TestRepositoriesService_RequestPageBuild(t *testing.T) { |
| 418 |
client, mux, _, teardown := setup() |
| 419 |
defer teardown() |
| 420 |
|
| 421 |
mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { |
| 422 |
testMethod(t, r, "POST") |
| 423 |
fmt.Fprint(w, `{"url":"u","status":"s"}`) |
| 424 |
}) |
| 425 |
|
| 426 |
ctx := context.Background() |
| 427 |
build, _, err := client.Repositories.RequestPageBuild(ctx, "o", "r") |
| 428 |
if err != nil { |
| 429 |
t.Errorf("Repositories.RequestPageBuild returned error: %v", err) |
| 430 |
} |
| 431 |
|
| 432 |
want := &PagesBuild{URL: String("u"), Status: String("s")} |
| 433 |
if !cmp.Equal(build, want) { |
| 434 |
t.Errorf("Repositories.RequestPageBuild returned %+v, want %+v", build, want) |
| 435 |
} |
| 436 |
|
| 437 |
const methodName = "RequestPageBuild" |
| 438 |
testBadOptions(t, methodName, func() (err error) { |
| 439 |
_, _, err = client.Repositories.RequestPageBuild(ctx, "\n", "\n") |
| 440 |
return err |
| 441 |
}) |
| 442 |
|
| 443 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 444 |
got, resp, err := client.Repositories.RequestPageBuild(ctx, "o", "r") |
| 445 |
if got != nil { |
| 446 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 447 |
} |
| 448 |
return resp, err |
| 449 |
}) |
| 450 |
} |
| 451 |
|
| 452 |
func TestRepositoriesService_GetPageHealthCheck(t *testing.T) { |
| 453 |
client, mux, _, teardown := setup() |
| 454 |
defer teardown() |
| 455 |
|
| 456 |
mux.HandleFunc("/repos/o/r/pages/health", func(w http.ResponseWriter, r *http.Request) { |
| 457 |
testMethod(t, r, "GET") |
| 458 |
fmt.Fprint(w, `{"domain":{"host":"example.com","uri":"http://example.com/","nameservers":"default","dns_resolves":true},"alt_domain":{"host":"www.example.com","uri":"http://www.example.com/","nameservers":"default","dns_resolves":true}}`) |
| 459 |
}) |
| 460 |
|
| 461 |
ctx := context.Background() |
| 462 |
healthCheckResponse, _, err := client.Repositories.GetPageHealthCheck(ctx, "o", "r") |
| 463 |
if err != nil { |
| 464 |
t.Errorf("Repositories.GetPageHealthCheck returned error: %v", err) |
| 465 |
} |
| 466 |
|
| 467 |
want := &PagesHealthCheckResponse{ |
| 468 |
Domain: &PagesDomain{ |
| 469 |
Host: String("example.com"), |
| 470 |
URI: String("http://example.com/"), |
| 471 |
Nameservers: String("default"), |
| 472 |
DNSResolves: Bool(true), |
| 473 |
}, |
| 474 |
AltDomain: &PagesDomain{ |
| 475 |
Host: String("www.example.com"), |
| 476 |
URI: String("http://www.example.com/"), |
| 477 |
Nameservers: String("default"), |
| 478 |
DNSResolves: Bool(true), |
| 479 |
}, |
| 480 |
} |
| 481 |
if !cmp.Equal(healthCheckResponse, want) { |
| 482 |
t.Errorf("Repositories.GetPageHealthCheck returned %+v, want %+v", healthCheckResponse, want) |
| 483 |
} |
| 484 |
|
| 485 |
const methodName = "GetPageHealthCheck" |
| 486 |
testBadOptions(t, methodName, func() (err error) { |
| 487 |
_, _, err = client.Repositories.GetPageHealthCheck(ctx, "\n", "\n") |
| 488 |
return err |
| 489 |
}) |
| 490 |
|
| 491 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 492 |
got, resp, err := client.Repositories.GetPageHealthCheck(ctx, "o", "r") |
| 493 |
if got != nil { |
| 494 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 495 |
} |
| 496 |
return resp, err |
| 497 |
}) |
| 498 |
} |
| 499 |
|
| 500 |
func TestPagesSource_Marshal(t *testing.T) { |
| 501 |
testJSONMarshal(t, &PagesSource{}, "{}") |
| 502 |
|
| 503 |
u := &PagesSource{ |
| 504 |
Branch: String("branch"), |
| 505 |
Path: String("path"), |
| 506 |
} |
| 507 |
|
| 508 |
want := `{ |
| 509 |
"branch": "branch", |
| 510 |
"path": "path" |
| 511 |
}` |
| 512 |
|
| 513 |
testJSONMarshal(t, u, want) |
| 514 |
} |
| 515 |
|
| 516 |
func TestPagesError_Marshal(t *testing.T) { |
| 517 |
testJSONMarshal(t, &PagesError{}, "{}") |
| 518 |
|
| 519 |
u := &PagesError{ |
| 520 |
Message: String("message"), |
| 521 |
} |
| 522 |
|
| 523 |
want := `{ |
| 524 |
"message": "message" |
| 525 |
}` |
| 526 |
|
| 527 |
testJSONMarshal(t, u, want) |
| 528 |
} |
| 529 |
|
| 530 |
func TestPagesUpdate_Marshal(t *testing.T) { |
| 531 |
testJSONMarshal(t, &PagesUpdate{}, "{}") |
| 532 |
|
| 533 |
u := &PagesUpdate{ |
| 534 |
CNAME: String("cname"), |
| 535 |
Source: &PagesSource{Path: String("src")}, |
| 536 |
} |
| 537 |
|
| 538 |
want := `{ |
| 539 |
"cname": "cname", |
| 540 |
"source": { "path": "src" } |
| 541 |
}` |
| 542 |
|
| 543 |
testJSONMarshal(t, u, want) |
| 544 |
} |
| 545 |
|
| 546 |
func TestPages_Marshal(t *testing.T) { |
| 547 |
testJSONMarshal(t, &Pages{}, "{}") |
| 548 |
|
| 549 |
u := &Pages{ |
| 550 |
URL: String("url"), |
| 551 |
Status: String("status"), |
| 552 |
CNAME: String("cname"), |
| 553 |
Custom404: Bool(false), |
| 554 |
HTMLURL: String("hurl"), |
| 555 |
Source: &PagesSource{ |
| 556 |
Branch: String("branch"), |
| 557 |
Path: String("path"), |
| 558 |
}, |
| 559 |
} |
| 560 |
|
| 561 |
want := `{ |
| 562 |
"url": "url", |
| 563 |
"status": "status", |
| 564 |
"cname": "cname", |
| 565 |
"custom_404": false, |
| 566 |
"html_url": "hurl", |
| 567 |
"source": { |
| 568 |
"branch": "branch", |
| 569 |
"path": "path" |
| 570 |
} |
| 571 |
}` |
| 572 |
|
| 573 |
testJSONMarshal(t, u, want) |
| 574 |
} |
| 575 |
|
| 576 |
func TestPagesBuild_Marshal(t *testing.T) { |
| 577 |
testJSONMarshal(t, &PagesBuild{}, "{}") |
| 578 |
|
| 579 |
u := &PagesBuild{ |
| 580 |
URL: String("url"), |
| 581 |
Status: String("status"), |
| 582 |
Error: &PagesError{ |
| 583 |
Message: String("message"), |
| 584 |
}, |
| 585 |
Pusher: &User{ID: Int64(1)}, |
| 586 |
Commit: String("commit"), |
| 587 |
Duration: Int(1), |
| 588 |
CreatedAt: &Timestamp{referenceTime}, |
| 589 |
UpdatedAt: &Timestamp{referenceTime}, |
| 590 |
} |
| 591 |
|
| 592 |
want := `{ |
| 593 |
"url": "url", |
| 594 |
"status": "status", |
| 595 |
"error": { |
| 596 |
"message": "message" |
| 597 |
}, |
| 598 |
"pusher": { |
| 599 |
"id": 1 |
| 600 |
}, |
| 601 |
"commit": "commit", |
| 602 |
"duration": 1, |
| 603 |
"created_at": ` + referenceTimeStr + `, |
| 604 |
"updated_at": ` + referenceTimeStr + ` |
| 605 |
}` |
| 606 |
|
| 607 |
testJSONMarshal(t, u, want) |
| 608 |
} |
| 609 |
|
| 610 |
func TestPagesHealthCheckResponse_Marshal(t *testing.T) { |
| 611 |
testJSONMarshal(t, &PagesHealthCheckResponse{}, "{}") |
| 612 |
|
| 613 |
u := &PagesHealthCheckResponse{ |
| 614 |
Domain: &PagesDomain{ |
| 615 |
Host: String("example.com"), |
| 616 |
URI: String("http://example.com/"), |
| 617 |
Nameservers: String("default"), |
| 618 |
DNSResolves: Bool(true), |
| 619 |
IsProxied: Bool(false), |
| 620 |
IsCloudflareIP: Bool(false), |
| 621 |
IsFastlyIP: Bool(false), |
| 622 |
IsOldIPAddress: Bool(false), |
| 623 |
IsARecord: Bool(true), |
| 624 |
HasCNAMERecord: Bool(false), |
| 625 |
HasMXRecordsPresent: Bool(false), |
| 626 |
IsValidDomain: Bool(true), |
| 627 |
IsApexDomain: Bool(true), |
| 628 |
ShouldBeARecord: Bool(true), |
| 629 |
IsCNAMEToGithubUserDomain: Bool(false), |
| 630 |
IsCNAMEToPagesDotGithubDotCom: Bool(false), |
| 631 |
IsCNAMEToFastly: Bool(false), |
| 632 |
IsPointedToGithubPagesIP: Bool(true), |
| 633 |
IsNonGithubPagesIPPresent: Bool(false), |
| 634 |
IsPagesDomain: Bool(false), |
| 635 |
IsServedByPages: Bool(true), |
| 636 |
IsValid: Bool(true), |
| 637 |
Reason: String("some reason"), |
| 638 |
RespondsToHTTPS: Bool(true), |
| 639 |
EnforcesHTTPS: Bool(true), |
| 640 |
HTTPSError: String("some error"), |
| 641 |
IsHTTPSEligible: Bool(true), |
| 642 |
CAAError: String("some error"), |
| 643 |
}, |
| 644 |
AltDomain: &PagesDomain{ |
| 645 |
Host: String("www.example.com"), |
| 646 |
URI: String("http://www.example.com/"), |
| 647 |
Nameservers: String("default"), |
| 648 |
DNSResolves: Bool(true), |
| 649 |
}, |
| 650 |
} |
| 651 |
|
| 652 |
want := `{ |
| 653 |
"domain": { |
| 654 |
"host": "example.com", |
| 655 |
"uri": "http://example.com/", |
| 656 |
"nameservers": "default", |
| 657 |
"dns_resolves": true, |
| 658 |
"is_proxied": false, |
| 659 |
"is_cloudflare_ip": false, |
| 660 |
"is_fastly_ip": false, |
| 661 |
"is_old_ip_address": false, |
| 662 |
"is_a_record": true, |
| 663 |
"has_cname_record": false, |
| 664 |
"has_mx_records_present": false, |
| 665 |
"is_valid_domain": true, |
| 666 |
"is_apex_domain": true, |
| 667 |
"should_be_a_record": true, |
| 668 |
"is_cname_to_github_user_domain": false, |
| 669 |
"is_cname_to_pages_dot_github_dot_com": false, |
| 670 |
"is_cname_to_fastly": false, |
| 671 |
"is_pointed_to_github_pages_ip": true, |
| 672 |
"is_non_github_pages_ip_present": false, |
| 673 |
"is_pages_domain": false, |
| 674 |
"is_served_by_pages": true, |
| 675 |
"is_valid": true, |
| 676 |
"reason": "some reason", |
| 677 |
"responds_to_https": true, |
| 678 |
"enforces_https": true, |
| 679 |
"https_error": "some error", |
| 680 |
"is_https_eligible": true, |
| 681 |
"caa_error": "some error" |
| 682 |
}, |
| 683 |
"alt_domain": { |
| 684 |
"host": "www.example.com", |
| 685 |
"uri": "http://www.example.com/", |
| 686 |
"nameservers": "default", |
| 687 |
"dns_resolves": true |
| 688 |
} |
| 689 |
}` |
| 690 |
|
| 691 |
testJSONMarshal(t, u, want) |
| 692 |
} |
| 693 |
|
| 694 |
func TestCreatePagesRequest_Marshal(t *testing.T) { |
| 695 |
testJSONMarshal(t, &createPagesRequest{}, "{}") |
| 696 |
|
| 697 |
u := &createPagesRequest{ |
| 698 |
Source: &PagesSource{ |
| 699 |
Branch: String("branch"), |
| 700 |
Path: String("path"), |
| 701 |
}, |
| 702 |
} |
| 703 |
|
| 704 |
want := `{ |
| 705 |
"source": { |
| 706 |
"branch": "branch", |
| 707 |
"path": "path" |
| 708 |
} |
| 709 |
}` |
| 710 |
|
| 711 |
testJSONMarshal(t, u, want) |
| 712 |
} |