Skip to content

Commit 120ba10

Browse files
authored
Merge branch 'main' into bricksroo/html-rewriter-docs-fix
2 parents c99e389 + d80454a commit 120ba10

File tree

3 files changed

+95
-59
lines changed

3 files changed

+95
-59
lines changed

integration-tests/js-compute/cleanupAll.js

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ const {
1414
SECRET_STORE_PREFIX,
1515
} = getPrefixes();
1616

17-
function existingListIds(stores, prefix) {
18-
return stores
19-
.filter(
20-
(store) =>
21-
store.name?.startsWith(prefix) || store.Name?.startsWith(prefix),
22-
)
23-
.map((existing) => existing.id || existing.StoreID);
17+
function existingList(stores, prefix) {
18+
return stores.filter(
19+
(store) => store.name?.startsWith(prefix) || store.Name?.startsWith(prefix),
20+
);
2421
}
2522

2623
const startTime = Date.now();
@@ -42,100 +39,130 @@ if (process.env.FASTLY_API_TOKEN === undefined) {
4239
}
4340
const FASTLY_API_TOKEN = process.env.FASTLY_API_TOKEN;
4441

45-
async function removeConfigStores(links, serviceIds) {
42+
async function removeConfigStores(links, services) {
43+
console.log('Removing config stores...');
4644
const stores = JSON.parse(
4745
await zx`fastly config-store list --quiet --json --token $FASTLY_API_TOKEN`,
4846
);
4947

50-
let STORE_IDS = existingListIds(stores, DICTIONARY_PREFIX);
51-
for (const STORE_ID of STORE_IDS) {
52-
await zx`fastly config-store delete --store-id=${STORE_ID} --token $FASTLY_API_TOKEN`;
48+
let dictionaries = existingList(stores, DICTIONARY_PREFIX);
49+
for (const dictionary of dictionaries) {
50+
console.log(`\tDeleting dictionary ${dictionary.name}`);
51+
try {
52+
await zx`fastly config-store delete --store-id=${dictionary.id} --token $FASTLY_API_TOKEN`;
53+
} catch {}
5354
}
55+
console.log('All dictionaries removed');
5456

55-
STORE_IDS = existingListIds(stores, CONFIG_STORE_PREFIX);
56-
for (const STORE_ID of STORE_IDS) {
57+
let configStores = existingList(stores, CONFIG_STORE_PREFIX);
58+
for (const store of configStores) {
59+
console.log(`\tDeleting config store ${store.name}`);
5760
try {
58-
await zx`fastly config-store delete --store-id=${STORE_ID} --token $FASTLY_API_TOKEN`;
61+
await zx`fastly config-store delete --store-id=${store.id} --token $FASTLY_API_TOKEN`;
5962
} catch {}
6063
}
64+
console.log('All config stores removed');
6165
}
6266

6367
async function removeKVStores() {
68+
console.log('Removing KV stores...');
6469
const stores = JSON.parse(
6570
await zx`fastly kv-store list --quiet --json --token $FASTLY_API_TOKEN`,
6671
).Data;
6772

68-
let STORE_IDS = existingListIds(stores, KV_STORE_PREFIX);
69-
for (const STORE_ID of STORE_IDS) {
70-
await zx`fastly kv-store delete --store-id=${STORE_ID} --quiet --all -y --token $FASTLY_API_TOKEN`;
73+
let kvStores = existingList(stores, KV_STORE_PREFIX);
74+
for (const store of kvStores) {
75+
console.log(`\tDeleting KV store ${store.Name}`);
76+
try {
77+
await zx`fastly kv-store delete --store-id=${store.StoreID} --quiet --all -y --token $FASTLY_API_TOKEN`;
78+
} catch {}
7179
}
80+
console.log('All KV stores removed');
7281
}
7382

74-
async function removeSecretStores(serviceIds) {
83+
async function removeSecretStores(services) {
84+
console.log('Removing secret stores...');
7585
const stores = JSON.parse(
7686
await zx`fastly secret-store list --quiet --json --token $FASTLY_API_TOKEN`,
7787
);
7888
if (!stores) {
7989
return;
8090
}
81-
const STORE_IDS = existingListIds(stores, SECRET_STORE_PREFIX);
82-
for (const STORE_ID of STORE_IDS) {
91+
const secretStores = existingList(stores, SECRET_STORE_PREFIX);
92+
for (const store of secretStores) {
93+
console.log(`\tDeleting secret store ${store.name}`);
8394
try {
84-
await zx`fastly secret-store delete --store-id=${STORE_ID} --token $FASTLY_API_TOKEN`;
95+
await zx`fastly secret-store delete --store-id=${store.id} --token $FASTLY_API_TOKEN`;
8596
} catch {}
8697
}
98+
console.log('All secret stores removed');
8799
}
88100

89-
async function removeAcls(serviceIds) {
90-
const ACL_IDS = existingListIds(
101+
async function removeAcls(services) {
102+
console.log('Removing ACLs...');
103+
const acls = existingList(
91104
JSON.parse(
92105
await zx`fastly compute acl list-acls --quiet --json --token $FASTLY_API_TOKEN`,
93106
).data,
94107
ACL_PREFIX,
95108
);
96109

97-
for (const ACL_ID of ACL_IDS) {
98-
await zx`fastly compute acl delete --acl-id=${ACL_ID} --token $FASTLY_API_TOKEN`;
110+
for (const acl of acls) {
111+
console.log(`\tDeleting acl ${acl.name}`);
112+
try {
113+
await zx`fastly compute acl delete --acl-id=${acl.id} --token $FASTLY_API_TOKEN`;
114+
} catch {}
99115
}
116+
console.log('All ACLs removed');
100117
}
101118

102-
async function getServiceIds() {
119+
async function getServices() {
120+
console.log('Getting services...');
103121
let services = JSON.parse(
104122
await zx`fastly service list --token $FASTLY_API_TOKEN --json`,
105123
);
106-
return services
107-
.filter(({ Name }) => Name.startsWith(SERVICE_PREFIX))
108-
.map((service) => service.ServiceID);
124+
services = services.filter(({ Name }) => Name.startsWith(SERVICE_PREFIX));
125+
console.log('Services to delete:');
126+
for (const service of services) {
127+
console.log('\t', service.Name);
128+
}
129+
return services;
109130
}
110131

111-
async function removeServices(serviceIds) {
112-
for (const serviceId of serviceIds) {
113-
await zx`fastly service delete --force --service-id=${serviceId}`;
132+
async function removeServices(services) {
133+
console.log('Removing services...');
134+
for (const service of services) {
135+
console.log(`\tDeleting service ${service.Name}`);
136+
await zx`fastly service delete --force --service-id=${service.ServiceID}`;
114137
}
138+
console.log('ALl services removed');
115139
}
116140

117-
async function removeLinks(serviceIds) {
118-
for (const serviceId of serviceIds) {
141+
async function removeLinks(services) {
142+
console.log('Removing links...');
143+
for (const service of services) {
119144
const links = JSON.parse(
120-
await zx`fastly resource-link list --service-id=${serviceId} --quiet --json --version latest --token $FASTLY_API_TOKEN`,
145+
await zx`fastly resource-link list --service-id=${service.ServiceID} --quiet --json --version latest --token $FASTLY_API_TOKEN`,
121146
);
122147
for (const link of links) {
148+
console.log(
149+
`\tDeleting link between service ${service.Name} and resource ${link.name}`,
150+
);
123151
await zx`fastly resource-link delete --version latest --autoclone --id=${link.id} --service-id=${link.service_id} --token $FASTLY_API_TOKEN`;
124152
await zx`fastly service-version activate --version latest --service-id=${link.service_id} --token $FASTLY_API_TOKEN`;
125153
}
126154
}
155+
console.log('All links removed');
127156
}
128157

129-
const serviceIds = await getServiceIds();
130-
await removeLinks(serviceIds);
131-
await Promise.all([
132-
removeConfigStores(serviceIds),
133-
removeKVStores(),
134-
removeSecretStores(serviceIds),
135-
removeAcls(serviceIds),
136-
]);
137-
await removeServices(serviceIds);
158+
const services = await getServices();
159+
await removeLinks(services);
160+
await removeConfigStores(services);
161+
await removeKVStores();
162+
await removeSecretStores(services);
163+
await removeAcls(services);
164+
await removeServices(services);
138165

139166
console.log(
140-
`Tear down has finished! Took ${(Date.now() - startTime) / 1000} seconds to complete`,
167+
`Cleanup has finished! Took ${(Date.now() - startTime) / 1000} seconds to complete`,
141168
);
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1+
export const GLOBAL_PREFIX = 'js_integration_test_';
2+
3+
function applyGlobalPrefix(map) {
4+
for (const key in map) {
5+
map[key] = GLOBAL_PREFIX + map[key];
6+
}
7+
return map;
8+
}
9+
110
export function getEnv(serviceName) {
2-
return {
11+
return applyGlobalPrefix({
312
DICTIONARY_NAME: `aZ2__2${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`,
4-
CONFIG_STORE_NAME: `testconfig${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`,
5-
KV_STORE_NAME: `example-test-kv-store${serviceName ? '--' + serviceName : ''}`,
6-
SECRET_STORE_NAME: `example-test-secret-store${serviceName ? '--' + serviceName : ''}`,
7-
ACL_NAME: `exampleacl${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`,
8-
};
13+
CONFIG_STORE_NAME: `config${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`,
14+
KV_STORE_NAME: `kv-store${serviceName ? '--' + serviceName : ''}`,
15+
SECRET_STORE_NAME: `secret-store${serviceName ? '--' + serviceName : ''}`,
16+
ACL_NAME: `acl${serviceName ? '__' + serviceName.replace(/-/g, '_') : ''}`,
17+
});
918
}
1019

1120
export function getPrefixes() {
12-
return {
21+
return applyGlobalPrefix({
1322
SERVICE_PREFIX: `app-`,
1423
DICTIONARY_PREFIX: `aZ2__2`,
15-
CONFIG_STORE_PREFIX: `testconfig`,
16-
KV_STORE_PREFIX: `example-test-kv-store`,
17-
SECRET_STORE_PREFIX: `example-test-secret-store`,
18-
ACL_PREFIX: `exampleacl`,
19-
};
24+
CONFIG_STORE_PREFIX: `config`,
25+
KV_STORE_PREFIX: `kv-store`,
26+
SECRET_STORE_PREFIX: `secret-store`,
27+
ACL_PREFIX: `acl`,
28+
});
2029
}

integration-tests/js-compute/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { existsSync } from 'node:fs';
1010
import { copyFile, readFile, writeFile } from 'node:fs/promises';
1111
import core from '@actions/core';
1212
import TOML from '@iarna/toml';
13-
import { getEnv } from './env.js';
13+
import { getEnv, GLOBAL_PREFIX } from './env.js';
1414

1515
// test environment variable handling
1616
process.env.LOCAL_TEST = 'local val';
@@ -81,7 +81,7 @@ const branchName = (await zx`git branch --show-current`).stdout
8181
const fixture = !moduleMode ? 'app' : 'module-mode';
8282

8383
// Service names are carefully unique to support parallel runs
84-
const serviceName = `app-${branchName}${aot ? '--aot' : ''}${httpCache ? '--http' : ''}${process.env.SUFFIX_STRING ? '--' + process.env.SUFFIX_STRING : ''}`;
84+
const serviceName = `${GLOBAL_PREFIX}app-${branchName}${aot ? '--aot' : ''}${httpCache ? '--http' : ''}${process.env.SUFFIX_STRING ? '--' + process.env.SUFFIX_STRING : ''}`;
8585
let domain, serviceId;
8686
const fixturePath = join(__dirname, 'fixtures', fixture);
8787
let localServer;

0 commit comments

Comments
 (0)