|
1 | 1 | # Unit tests for some chartpress methods |
2 | 2 | from os import mkdir |
3 | 3 |
|
| 4 | +import git |
4 | 5 | import pytest |
5 | 6 | from ruamel.yaml import YAML |
6 | 7 |
|
@@ -405,3 +406,103 @@ def test_publish_pages(git_repo, mock_check_call): |
405 | 406 | ["git", "push", "origin", "gh-pages"], |
406 | 407 | {"cwd": "test-chart-1.2.3"}, |
407 | 408 | ) |
| 409 | + |
| 410 | + |
| 411 | +def test_publish_pages_firsttime(git_repo_mainonly, record_check_call): |
| 412 | + chartpress.publish_pages( |
| 413 | + "testchart", |
| 414 | + "1.2.3", |
| 415 | + "https://github.com/jupyterhub/chartpress", |
| 416 | + "https://example.org/chartpress", |
| 417 | + "<foo>", |
| 418 | + push=False, |
| 419 | + ) |
| 420 | + |
| 421 | + assert len(record_check_call.commands) == 7 |
| 422 | + |
| 423 | + assert record_check_call.commands[0] == ( |
| 424 | + [ |
| 425 | + "git", |
| 426 | + "clone", |
| 427 | + "--no-checkout", |
| 428 | + "https://github.com/jupyterhub/chartpress", |
| 429 | + "testchart-1.2.3", |
| 430 | + ], |
| 431 | + {"echo": True}, |
| 432 | + ) |
| 433 | + assert record_check_call.commands[1] == ( |
| 434 | + ["git", "checkout", "gh-pages"], |
| 435 | + {"cwd": "testchart-1.2.3", "echo": True}, |
| 436 | + ) |
| 437 | + |
| 438 | + assert record_check_call.commands[2] == ( |
| 439 | + ["git", "switch", "--orphan", "gh-pages"], |
| 440 | + {"cwd": "testchart-1.2.3", "echo": True}, |
| 441 | + ) |
| 442 | + |
| 443 | + helm_package_cmd = record_check_call.commands[3][0] |
| 444 | + assert record_check_call.commands[3][1] == {} |
| 445 | + # Skip the temporary directory |
| 446 | + assert (helm_package_cmd[:5] + helm_package_cmd[6:]) == [ |
| 447 | + "helm", |
| 448 | + "package", |
| 449 | + "testchart", |
| 450 | + "--dependency-update", |
| 451 | + "--destination", |
| 452 | + ] |
| 453 | + |
| 454 | + helm_index_cmd = record_check_call.commands[4][0] |
| 455 | + assert record_check_call.commands[4][1] == {} |
| 456 | + # Skip the temporary directory |
| 457 | + assert (helm_index_cmd[:3] + helm_index_cmd[4:]) == [ |
| 458 | + "helm", |
| 459 | + "repo", |
| 460 | + "index", |
| 461 | + "--url", |
| 462 | + "https://example.org/chartpress", |
| 463 | + "--merge", |
| 464 | + "testchart-1.2.3/index.yaml", |
| 465 | + ] |
| 466 | + |
| 467 | + assert record_check_call.commands[5] == ( |
| 468 | + ["git", "add", "."], |
| 469 | + {"cwd": "testchart-1.2.3"}, |
| 470 | + ) |
| 471 | + assert record_check_call.commands[6] == ( |
| 472 | + [ |
| 473 | + "git", |
| 474 | + "commit", |
| 475 | + "-m", |
| 476 | + "[testchart] Automatic update for commit 1.2.3\n\n<foo>", |
| 477 | + ], |
| 478 | + {"cwd": "testchart-1.2.3"}, |
| 479 | + ) |
| 480 | + |
| 481 | + with open("testchart-1.2.3/index.yaml") as f: |
| 482 | + chart = YAML(typ="safe").load(f) |
| 483 | + |
| 484 | + chart["entries"]["testchart"][0]["created"] = "DATETIME" |
| 485 | + chart["entries"]["testchart"][0]["digest"] = "DIGEST" |
| 486 | + chart["generated"] = "DATETIME" |
| 487 | + |
| 488 | + assert chart == { |
| 489 | + "apiVersion": "v1", |
| 490 | + "entries": { |
| 491 | + "testchart": [ |
| 492 | + { |
| 493 | + "apiVersion": "v1", |
| 494 | + "created": "DATETIME", |
| 495 | + "digest": "DIGEST", |
| 496 | + "name": "testchart", |
| 497 | + "urls": [ |
| 498 | + "https://example.org/chartpress/testchart-0.0.1-test.reset.version.tgz" |
| 499 | + ], |
| 500 | + "version": "0.0.1-test.reset.version", |
| 501 | + } |
| 502 | + ] |
| 503 | + }, |
| 504 | + "generated": "DATETIME", |
| 505 | + } |
| 506 | + |
| 507 | + r = git.Repo("./testchart-1.2.3") |
| 508 | + assert sorted(b.name for b in r.branches) == ["gh-pages", "main"] |
0 commit comments