|
1 |
| -/* eslint-disable @typescript-eslint/no-non-null-assertion */ |
2 | 1 | ////////////////////////////////////////////////////////////////////////////////
|
3 | 2 | // !!NOTE!!
|
4 | 3 | // This test suite uses mock-fs to mock out the the file system
|
@@ -34,6 +33,7 @@ import {
|
34 | 33 | createTestServiceBuildAndUpdatePipelineYaml,
|
35 | 34 | } from "../test/mockFactory";
|
36 | 35 | import { AccessYaml, AzurePipelinesYaml, MaintainersFile } from "../types";
|
| 36 | +import { errorStatusCode } from "./errorStatusCode"; |
37 | 37 | import {
|
38 | 38 | addNewServiceToMaintainersFile,
|
39 | 39 | appendVariableGroupToPipelineYaml,
|
@@ -461,6 +461,17 @@ describe("appendVariableGroupToHldAzurePipelinesYaml", () => {
|
461 | 461 | createTestHldAzurePipelinesYamlWithVariableGroup()
|
462 | 462 | );
|
463 | 463 | });
|
| 464 | + it("negative test", () => { |
| 465 | + try { |
| 466 | + appendVariableGroupToPipelineYaml( |
| 467 | + uuid(), |
| 468 | + RENDER_HLD_PIPELINE_FILENAME, |
| 469 | + "my-vg" |
| 470 | + ); |
| 471 | + } catch (err) { |
| 472 | + expect(err.errorCode).toBe(errorStatusCode.FILE_IO_ERR); |
| 473 | + } |
| 474 | + }); |
464 | 475 | });
|
465 | 476 |
|
466 | 477 | describe("generateDefaultHldComponentYaml", () => {
|
@@ -667,26 +678,48 @@ describe("serviceBuildUpdatePipeline", () => {
|
667 | 678 | expect(deserializedYaml).toStrictEqual(buildPipelineYaml);
|
668 | 679 |
|
669 | 680 | // variables should include all groups
|
670 |
| - for (const group of variableGroups) { |
671 |
| - expect(buildPipelineYaml.variables!.includes({ group })); |
| 681 | + expect(buildPipelineYaml.variables).toBeDefined(); |
| 682 | + if (buildPipelineYaml.variables) { |
| 683 | + expect(buildPipelineYaml.variables.length).toBe(variableGroups.length); |
| 684 | + |
| 685 | + for (const group of variableGroups) { |
| 686 | + expect(buildPipelineYaml.variables.includes({ group })); |
| 687 | + } |
672 | 688 | }
|
673 |
| - expect(buildPipelineYaml.variables!.length).toBe(variableGroups.length); |
674 | 689 |
|
675 | 690 | // trigger branches should include all ring branches
|
676 |
| - for (const branch of ringBranches) { |
677 |
| - expect(buildPipelineYaml.trigger!.branches!.include!.includes(branch)); |
| 691 | + expect(buildPipelineYaml.trigger).toBeDefined(); |
| 692 | + if (buildPipelineYaml.trigger) { |
| 693 | + expect(buildPipelineYaml.trigger.branches).toBeDefined(); |
| 694 | + |
| 695 | + if (buildPipelineYaml.trigger.branches) { |
| 696 | + expect(buildPipelineYaml.trigger.branches.include).toBeDefined(); |
| 697 | + |
| 698 | + if (buildPipelineYaml.trigger.branches.include) { |
| 699 | + expect(buildPipelineYaml.trigger.branches.include.length).toBe( |
| 700 | + ringBranches.length |
| 701 | + ); |
| 702 | + for (const branch of ringBranches) { |
| 703 | + expect(buildPipelineYaml.trigger.branches.include.includes(branch)); |
| 704 | + } |
| 705 | + } |
| 706 | + } |
678 | 707 | }
|
679 |
| - expect(buildPipelineYaml.trigger!.branches!.include!.length).toBe( |
680 |
| - ringBranches.length |
681 |
| - ); |
682 | 708 |
|
683 | 709 | // verify components of stages
|
684 |
| - expect(buildPipelineYaml.stages && buildPipelineYaml.stages.length === 2); |
685 |
| - for (const stage of buildPipelineYaml.stages!) { |
686 |
| - for (const job of stage.jobs) { |
687 |
| - // pool.vmImage should be 'gentoo' |
688 |
| - expect(job.pool!.vmImage).toBe(VM_IMAGE); |
689 |
| - expect(job.steps); |
| 710 | + expect(buildPipelineYaml.stages).toBeDefined(); |
| 711 | + if (buildPipelineYaml.stages) { |
| 712 | + expect(buildPipelineYaml.stages && buildPipelineYaml.stages.length === 2); |
| 713 | + for (const stage of buildPipelineYaml.stages) { |
| 714 | + for (const job of stage.jobs) { |
| 715 | + expect(job.pool).toBeDefined(); |
| 716 | + |
| 717 | + if (job.pool) { |
| 718 | + // pool.vmImage should be 'gentoo' |
| 719 | + expect(job.pool.vmImage).toBe(VM_IMAGE); |
| 720 | + expect(job.steps); |
| 721 | + } |
| 722 | + } |
690 | 723 | }
|
691 | 724 | }
|
692 | 725 | });
|
@@ -723,28 +756,44 @@ describe("serviceBuildUpdatePipeline", () => {
|
723 | 756 | "utf8"
|
724 | 757 | )
|
725 | 758 | );
|
726 |
| - const hasCorrectIncludes = azureYaml.trigger!.paths!.include!.includes( |
727 |
| - path.relative(randomDirPath, serviceReference.servicePath) |
728 |
| - ); |
729 |
| - expect(hasCorrectIncludes).toBe(true); |
730 | 759 |
|
731 |
| - let hasCorrectVariableGroup1 = false; |
732 |
| - let hasCorrectVariableGroup2 = false; |
733 |
| - for (const value of Object.values(azureYaml.variables!)) { |
734 |
| - const item = value as { group: string }; |
| 760 | + expect(azureYaml.trigger).toBeDefined(); |
735 | 761 |
|
736 |
| - if (item.group === variableGroups[0]) { |
737 |
| - hasCorrectVariableGroup1 = true; |
738 |
| - } |
| 762 | + if (azureYaml.trigger) { |
| 763 | + expect(azureYaml.trigger.paths).toBeDefined(); |
| 764 | + |
| 765 | + if (azureYaml.trigger.paths) { |
| 766 | + expect(azureYaml.trigger.paths.include).toBeDefined(); |
739 | 767 |
|
740 |
| - if (item.group === variableGroups[1]) { |
741 |
| - hasCorrectVariableGroup2 = true; |
| 768 | + if (azureYaml.trigger.paths.include) { |
| 769 | + const hasCorrectIncludes = azureYaml.trigger.paths.include.includes( |
| 770 | + path.relative(randomDirPath, serviceReference.servicePath) |
| 771 | + ); |
| 772 | + expect(hasCorrectIncludes).toBe(true); |
| 773 | + } |
742 | 774 | }
|
743 | 775 | }
|
744 | 776 |
|
745 |
| - expect(hasCorrectIncludes).toBe(true); |
746 |
| - expect(hasCorrectVariableGroup1).toBe(true); |
747 |
| - expect(hasCorrectVariableGroup2).toBe(true); |
| 777 | + expect(azureYaml.variables).toBeDefined(); |
| 778 | + |
| 779 | + if (azureYaml.variables) { |
| 780 | + let hasCorrectVariableGroup1 = false; |
| 781 | + let hasCorrectVariableGroup2 = false; |
| 782 | + for (const value of Object.values(azureYaml.variables)) { |
| 783 | + const item = value as { group: string }; |
| 784 | + |
| 785 | + if (item.group === variableGroups[0]) { |
| 786 | + hasCorrectVariableGroup1 = true; |
| 787 | + } |
| 788 | + |
| 789 | + if (item.group === variableGroups[1]) { |
| 790 | + hasCorrectVariableGroup2 = true; |
| 791 | + } |
| 792 | + } |
| 793 | + |
| 794 | + expect(hasCorrectVariableGroup1).toBe(true); |
| 795 | + expect(hasCorrectVariableGroup2).toBe(true); |
| 796 | + } |
748 | 797 | }
|
749 | 798 | });
|
750 | 799 | });
|
|
0 commit comments