|
1 | 1 | import { expect } from "chai";
|
2 | 2 | import * as build from "../../../deploy/functions/build";
|
| 3 | +import { ParamValue } from "../../../deploy/functions/params"; |
3 | 4 |
|
4 | 5 | describe("toBackend", () => {
|
5 | 6 | it("populates backend info from Build", () => {
|
@@ -110,4 +111,49 @@ describe("toBackend", () => {
|
110 | 111 | ).to.have.members(["service-account-1@", "service-account-2@"]);
|
111 | 112 | }
|
112 | 113 | });
|
| 114 | + |
| 115 | + it("populates multiple param values", () => { |
| 116 | + const desiredBuild: build.Build = build.of({ |
| 117 | + func: { |
| 118 | + platform: "gcfv2", |
| 119 | + region: ["us-central1"], |
| 120 | + project: "project", |
| 121 | + runtime: "nodejs16", |
| 122 | + entryPoint: "func", |
| 123 | + maxInstances: "{{ params.maxinstances }}", |
| 124 | + minInstances: "{{ params.mininstances }}", |
| 125 | + serviceAccount: "{{ params.serviceaccount }}", |
| 126 | + vpc: { |
| 127 | + connector: "projects/project/locations/region/connectors/connector", |
| 128 | + egressSettings: "PRIVATE_RANGES_ONLY", |
| 129 | + }, |
| 130 | + ingressSettings: "ALLOW_ALL", |
| 131 | + labels: { |
| 132 | + test: "testing", |
| 133 | + }, |
| 134 | + httpsTrigger: { |
| 135 | + invoker: ["service-account-2@", "service-account-3@"], |
| 136 | + }, |
| 137 | + }, |
| 138 | + }); |
| 139 | + const backend = build.toBackend(desiredBuild, { |
| 140 | + maxinstances: new ParamValue("42", false, { number: true }), |
| 141 | + mininstances: new ParamValue("1", false, { number: true }), |
| 142 | + serviceaccount: new ParamValue("service-account-1@", false, { string: true }), |
| 143 | + }); |
| 144 | + expect(Object.keys(backend.endpoints).length).to.equal(1); |
| 145 | + const endpointDef = Object.values(backend.endpoints)[0]; |
| 146 | + expect(endpointDef).to.not.equal(undefined); |
| 147 | + if (endpointDef) { |
| 148 | + expect(endpointDef.func.id).to.equal("func"); |
| 149 | + expect(endpointDef.func.project).to.equal("project"); |
| 150 | + expect(endpointDef.func.region).to.equal("us-central1"); |
| 151 | + expect(endpointDef.func.maxInstances).to.equal(42); |
| 152 | + expect(endpointDef.func.minInstances).to.equal(1); |
| 153 | + expect(endpointDef.func.serviceAccount).to.equal("service-account-1@"); |
| 154 | + expect( |
| 155 | + "httpsTrigger" in endpointDef.func ? endpointDef.func.httpsTrigger.invoker : [] |
| 156 | + ).to.have.members(["service-account-2@", "service-account-3@"]); |
| 157 | + } |
| 158 | + }); |
113 | 159 | });
|
0 commit comments