-
Notifications
You must be signed in to change notification settings - Fork 903
/
planner.spec.ts
195 lines (179 loc) · 5.97 KB
/
planner.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { expect } from "chai";
import * as sinon from "sinon";
import * as planner from "../../../deploy/extensions/planner";
import * as extensionsApi from "../../../extensions/extensionsApi";
import { ExtensionInstance } from "../../../extensions/types";
function extensionVersion(version?: string): any {
return {
name: `publishers/test/extensions/test/versions/${version}`,
ref: `test/test@${version}`,
state: "PUBLISHED",
hash: "abc123",
sourceDownloadUri: "https://google.com",
spec: {
name: "test",
version,
resources: [],
sourceUrl: "https://google.com",
params: [],
},
};
}
describe("Extensions Deployment Planner", () => {
describe("resolveSemver", () => {
let listExtensionVersionsStub: sinon.SinonStub;
before(() => {
listExtensionVersionsStub = sinon.stub(extensionsApi, "listExtensionVersions").resolves([
extensionVersion("0.1.0"),
extensionVersion("0.1.1"),
extensionVersion("0.2.0"),
extensionVersion(), // Explicitly test that this doesn't break on bad data
]);
});
after(() => {
listExtensionVersionsStub.restore();
});
const cases = [
{
description: "should return the latest version that satisifies a semver range",
in: "^0.1.0",
out: "0.1.1",
err: false,
},
{
description: "should match exact semver",
in: "0.2.0",
out: "0.2.0",
err: false,
},
{
description: "should resolve latest to a version",
in: "latest",
out: "0.2.0",
err: false,
},
{
description: "should default to latest version",
out: "0.2.0",
err: false,
},
{
description: "should error if there is no matching version",
in: "^0.3.0",
err: true,
},
];
for (const c of cases) {
it(c.description, () => {
if (!c.err) {
expect(
planner.resolveVersion({
publisherId: "test",
extensionId: "test",
version: c.in,
})
).to.eventually.equal(c.out);
} else {
expect(
planner.resolveVersion({
publisherId: "test",
extensionId: "test",
version: c.in,
})
).to.eventually.be.rejected;
}
});
}
});
describe("have", () => {
let listInstancesStub: sinon.SinonStub;
const SPEC = {
version: "0.1.0",
author: {
authorName: "Firebase",
url: "https://firebase.google.com",
},
resources: [],
name: "",
sourceUrl: "",
params: [],
};
const INSTANCE_WITH_EVENTS: ExtensionInstance = {
name: "projects/my-test-proj/instances/image-resizer",
createTime: "2019-05-19T00:20:10.416947Z",
updateTime: "2019-05-19T00:20:10.416947Z",
state: "ACTIVE",
serviceAccountEmail: "",
etag: "123456",
config: {
params: {},
extensionRef: "firebase/image-resizer",
extensionVersion: "0.1.0",
name: "projects/my-test-proj/instances/image-resizer/configurations/95355951-397f-4821-a5c2-9c9788b2cc63",
createTime: "2019-05-19T00:20:10.416947Z",
eventarcChannel: "projects/my-test-proj/locations/us-central1/channels/firebase",
allowedEventTypes: ["google.firebase.custom-event-occurred"],
source: {
state: "ACTIVE",
spec: SPEC,
name: "",
packageUri: "",
hash: "",
},
},
};
const INSTANCE_SPEC_WITH_EVENTS: planner.DeploymentInstanceSpec = {
instanceId: "image-resizer",
params: {},
allowedEventTypes: ["google.firebase.custom-event-occurred"],
eventarcChannel: "projects/my-test-proj/locations/us-central1/channels/firebase",
etag: "123456",
ref: {
publisherId: "firebase",
extensionId: "image-resizer",
version: "0.1.0",
},
};
const INSTANCE_WITH_UNDEFINED_EVENTS_CONFIG = JSON.parse(JSON.stringify(INSTANCE_WITH_EVENTS));
INSTANCE_WITH_UNDEFINED_EVENTS_CONFIG.config.eventarcChannel = undefined;
INSTANCE_WITH_UNDEFINED_EVENTS_CONFIG.config.allowedEventTypes = undefined;
const INSTANCE_SPEC_WITH_UNDEFINED_EVENTS_CONFIG = JSON.parse(
JSON.stringify(INSTANCE_SPEC_WITH_EVENTS)
);
INSTANCE_SPEC_WITH_UNDEFINED_EVENTS_CONFIG.eventarcChannel = undefined;
INSTANCE_SPEC_WITH_UNDEFINED_EVENTS_CONFIG.allowedEventTypes = undefined;
const INSTANCE_WITH_EMPTY_EVENTS_CONFIG = JSON.parse(JSON.stringify(INSTANCE_WITH_EVENTS));
INSTANCE_WITH_EMPTY_EVENTS_CONFIG.config.eventarcChannel = "";
INSTANCE_WITH_EMPTY_EVENTS_CONFIG.config.allowedEventTypes = [];
const INSTANCE_SPEC_WITH_EMPTY_EVENTS_CONFIG = JSON.parse(
JSON.stringify(INSTANCE_SPEC_WITH_EVENTS)
);
INSTANCE_SPEC_WITH_EMPTY_EVENTS_CONFIG.eventarcChannel = "";
INSTANCE_SPEC_WITH_EMPTY_EVENTS_CONFIG.allowedEventTypes = [];
const cases = [
{
description: "have() should return correct instance spec with events",
instances: [INSTANCE_WITH_EVENTS],
instanceSpecs: [INSTANCE_SPEC_WITH_EVENTS],
},
{
description: "have() should return correct instance spec with undefined events config",
instances: [INSTANCE_WITH_UNDEFINED_EVENTS_CONFIG],
instanceSpecs: [INSTANCE_SPEC_WITH_UNDEFINED_EVENTS_CONFIG],
},
{
description: "have() should return correct instance spec with empty events config",
instances: [INSTANCE_WITH_EMPTY_EVENTS_CONFIG],
instanceSpecs: [INSTANCE_SPEC_WITH_EMPTY_EVENTS_CONFIG],
},
];
for (const c of cases) {
it(c.description, async () => {
listInstancesStub = sinon.stub(extensionsApi, "listInstances").resolves(c.instances);
const have = await planner.have("test");
expect(have).to.have.same.deep.members(c.instanceSpecs);
listInstancesStub.restore();
});
}
});
});