/
manifest.spec.ts
170 lines (163 loc) · 4.26 KB
/
manifest.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { expect } from "chai";
import { stackToWire, ManifestStack } from "../../src/runtime/manifest";
import * as params from "../../src/params";
import * as optsv2 from "../../src/v2/options";
import * as v1 from "../../src/v1";
describe("stackToWire", () => {
afterEach(() => {
params.clearParams();
});
it("converts regular expressions used in param inputs", () => {
const regExpParam = params.defineString("foo", {
input: { text: { validationRegex: /\d{5}/ } },
});
const stack: ManifestStack = {
endpoints: {},
requiredAPIs: [],
params: [regExpParam.toSpec()],
specVersion: "v1alpha1",
};
const expected = {
endpoints: {},
requiredAPIs: [],
params: [
{
name: "foo",
type: "string",
input: {
text: {
validationRegex: "\\d{5}",
},
},
},
],
specVersion: "v1alpha1",
};
expect(stackToWire(stack)).to.deep.equal(expected);
});
it("converts stack with null values", () => {
const stack: ManifestStack = {
endpoints: {
v2http: {
platform: "gcfv2",
entryPoint: "v2http",
labels: {},
httpsTrigger: {},
maxInstances: null,
},
},
requiredAPIs: [],
specVersion: "v1alpha1",
};
const expected = {
endpoints: {
v2http: {
platform: "gcfv2",
entryPoint: "v2http",
labels: {},
httpsTrigger: {},
maxInstances: null,
},
},
requiredAPIs: [],
specVersion: "v1alpha1",
};
expect(stackToWire(stack)).to.deep.equal(expected);
});
it("converts stack with RESET_VALUES", () => {
const stack: ManifestStack = {
endpoints: {
v1http: {
platform: "gcfv1",
entryPoint: "v1http",
labels: {},
httpsTrigger: {},
maxInstances: v1.RESET_VALUE,
},
v2http: {
platform: "gcfv2",
entryPoint: "v2http",
labels: {},
httpsTrigger: {},
maxInstances: optsv2.RESET_VALUE,
},
},
requiredAPIs: [],
specVersion: "v1alpha1",
};
const expected = {
endpoints: {
v1http: {
platform: "gcfv1",
entryPoint: "v1http",
labels: {},
httpsTrigger: {},
maxInstances: null,
},
v2http: {
platform: "gcfv2",
entryPoint: "v2http",
labels: {},
httpsTrigger: {},
maxInstances: null,
},
},
requiredAPIs: [],
specVersion: "v1alpha1",
};
expect(stackToWire(stack)).to.deep.equal(expected);
});
it("converts Expression types in endpoint options to CEL", () => {
const intParam = params.defineInt("foo", { default: 11 });
const stringParam = params.defineString("bar", {
default: "America/Los_Angeles",
});
const stack: ManifestStack = {
endpoints: {
v2http: {
platform: "gcfv2",
entryPoint: "v2http",
labels: {},
httpsTrigger: {},
concurrency: intParam,
maxInstances: intParam.equals(24).thenElse(-1, 1),
},
v2schedule: {
platform: "gcfv2",
entryPoint: "v2callable",
labels: {},
scheduleTrigger: {
schedule: stringParam.equals("America/Mexico_City").thenElse("mexico", "usa"),
timeZone: stringParam,
},
},
},
requiredAPIs: [],
specVersion: "v1alpha1",
};
const expected = {
endpoints: {
v2http: {
platform: "gcfv2",
entryPoint: "v2http",
labels: {},
httpsTrigger: {},
concurrency: "{{ params.foo }}",
maxInstances: "{{ params.foo == 24 ? -1 : 1 }}",
},
v2schedule: {
platform: "gcfv2",
entryPoint: "v2callable",
labels: {},
scheduleTrigger: {
schedule: '{{ params.bar == "America/Mexico_City" ? "mexico" : "usa" }}',
timeZone: "{{ params.bar }}",
},
},
},
requiredAPIs: [],
specVersion: "v1alpha1",
};
expect(stackToWire(stack)).to.deep.equal(expected);
});
});