Skip to content

Commit 51f726c

Browse files
committed
Add test case for serializing stack with RESET_VALUES.
1 parent ea4eb28 commit 51f726c

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

spec/runtime/manifest.spec.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { expect } from "chai";
22
import { stackToWire, ManifestStack } from "../../src/runtime/manifest";
33
import * as params from "../../src/params";
4+
import * as optsv2 from "../../src/v2/options";
5+
import * as v1 from "../../src/v1";
46

57
describe("stackToWire", () => {
68
afterEach(() => {
79
params.clearParams();
810
});
911

10-
it("converts stack with null values values", () => {
12+
it("converts stack with null values", () => {
1113
const stack: ManifestStack = {
1214
endpoints: {
1315
v2http: {
@@ -37,6 +39,50 @@ describe("stackToWire", () => {
3739
expect(stackToWire(stack)).to.deep.equal(expected);
3840
});
3941

42+
it("converts stack with RESET_VALUES", () => {
43+
const stack: ManifestStack = {
44+
endpoints: {
45+
v1http: {
46+
platform: "gcfv1",
47+
entryPoint: "v1http",
48+
labels: {},
49+
httpsTrigger: {},
50+
maxInstances: v1.RESET_VALUE,
51+
},
52+
v2http: {
53+
platform: "gcfv2",
54+
entryPoint: "v2http",
55+
labels: {},
56+
httpsTrigger: {},
57+
maxInstances: optsv2.RESET_VALUE,
58+
},
59+
},
60+
requiredAPIs: [],
61+
specVersion: "v1alpha1",
62+
};
63+
const expected = {
64+
endpoints: {
65+
v1http: {
66+
platform: "gcfv1",
67+
entryPoint: "v1http",
68+
labels: {},
69+
httpsTrigger: {},
70+
maxInstances: null,
71+
},
72+
v2http: {
73+
platform: "gcfv2",
74+
entryPoint: "v2http",
75+
labels: {},
76+
httpsTrigger: {},
77+
maxInstances: null,
78+
},
79+
},
80+
requiredAPIs: [],
81+
specVersion: "v1alpha1",
82+
};
83+
expect(stackToWire(stack)).to.deep.equal(expected);
84+
});
85+
4086
it("converts Expression types in endpoint options to CEL", () => {
4187
const intParam = params.defineInt("foo", { default: 11 });
4288
const stringParam = params.defineString("bar", {

src/runtime/manifest.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23+
import { ResetValue } from "../common/options";
2324
import { Expression } from "../params";
2425
import { WireParamSpec } from "../params/types";
2526

@@ -30,19 +31,19 @@ export interface ManifestEndpoint {
3031
entryPoint?: string;
3132
region?: string[];
3233
platform?: string;
33-
availableMemoryMb?: number | Expression<number>;
34-
maxInstances?: number | Expression<number>;
35-
minInstances?: number | Expression<number>;
36-
concurrency?: number | Expression<number>;
37-
serviceAccountEmail?: string;
38-
timeoutSeconds?: number | Expression<number>;
39-
cpu?: number | "gcf_gen1";
34+
availableMemoryMb?: number | Expression<number> | ResetValue;
35+
maxInstances?: number | Expression<number> | ResetValue;
36+
minInstances?: number | Expression<number> | ResetValue;
37+
concurrency?: number | Expression<number> | ResetValue;
38+
timeoutSeconds?: number | Expression<number> | ResetValue;
4039
vpc?: {
41-
connector: string | Expression<string>;
40+
connector: string | Expression<string> | ResetValue;
4241
egressSettings?: string;
4342
};
43+
ingressSettings?: string | ResetValue;
44+
serviceAccountEmail?: string;
45+
cpu?: number | "gcf_gen1";
4446
labels?: Record<string, string>;
45-
ingressSettings?: string;
4647
environmentVariables?: Record<string, string>;
4748
secretEnvironmentVariables?: Array<{ key: string; secret?: string }>;
4849

@@ -57,20 +58,20 @@ export interface ManifestEndpoint {
5758
eventFilterPathPatterns?: Record<string, string | Expression<string>>;
5859
channel?: string;
5960
eventType: string;
60-
retry: boolean | Expression<boolean>;
61+
retry: boolean | Expression<boolean> | ResetValue;
6162
region?: string;
62-
serviceAccountEmail?: string;
63+
serviceAccountEmail?: string | ResetValue;
6364
};
6465

6566
scheduleTrigger?: {
6667
schedule?: string | Expression<string>;
67-
timeZone?: string | Expression<string>;
68+
timeZone?: string | Expression<string> | ResetValue;
6869
retryConfig?: {
69-
retryCount?: number | Expression<number>;
70-
maxRetrySeconds?: string | Expression<string>;
71-
minBackoffSeconds?: string | Expression<string>;
72-
maxBackoffSeconds?: string | Expression<string>;
73-
maxDoublings?: number | Expression<number>;
70+
retryCount?: number | Expression<number> | ResetValue;
71+
maxRetrySeconds?: string | Expression<string> | ResetValue;
72+
minBackoffSeconds?: string | Expression<string> | ResetValue;
73+
maxBackoffSeconds?: string | Expression<string> | ResetValue;
74+
maxDoublings?: number | Expression<number> | ResetValue;
7475
};
7576
};
7677

@@ -107,6 +108,8 @@ export function stackToWire(stack: ManifestStack): Record<string, unknown> {
107108
for (const [key, val] of Object.entries(obj)) {
108109
if (val instanceof Expression) {
109110
obj[key] = val.toCEL();
111+
} else if (val instanceof ResetValue) {
112+
obj[key] = val.toJSON();
110113
} else if (typeof val === "object" && val !== null) {
111114
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
112115
traverse(val as any);

src/v2/options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ export interface GlobalOptions {
168168
*/
169169
ingressSettings?: IngressSetting | ResetValue;
170170

171+
/**
172+
* Invoker to set access control on https functions.
173+
*/
174+
invoker?: "public" | "private" | string | string[];
175+
171176
/**
172177
* User labels to set on the function.
173178
*/

0 commit comments

Comments
 (0)