Skip to content

Commit 8ce8e16

Browse files
committed
cleanup serverless after each use
1 parent a986e21 commit 8ce8e16

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

packages/flex-plugin-e2e-tests/src/utils/plugins-api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {
1212
ConfiguredPluginResourcePage,
1313
} from 'flex-plugins-api-client';
1414
import { PluginServiceHttpOption } from 'flex-plugins-api-client/dist/clients/client';
15+
import { logger } from 'flex-dev-utils';
1516

1617
import { testParams } from '../core';
18+
import * as serverlessApi from './serverless-api';
1719

1820
const options: PluginServiceHttpOption = {};
1921
if (testParams.config.region) {
@@ -33,6 +35,8 @@ const configuredPluginsClient = new ConfiguredPluginsClient(client);
3335
const releasesClient = new ReleasesClient(client);
3436

3537
const cleanup = async (): Promise<void> => {
38+
logger.info('Cleaning up plugins-api');
39+
3640
// Fetch active plugin - later we will clean archive every entry
3741
const activeRelease = await releasesClient.active();
3842

@@ -53,6 +57,10 @@ const cleanup = async (): Promise<void> => {
5357
await versionsClient.archive(plugin.plugin_sid, plugin.plugin_version_sid);
5458
}
5559
}
60+
61+
// Remove serverless files
62+
const service = await serverlessApi.getServiceSid();
63+
await serverlessApi.deleteEnvironments(service.sid);
5664
};
5765

5866
const getPluginVersion = async (name: string, version: string): Promise<PluginVersionResource> => {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import axios from 'axios';
2+
3+
import { testParams } from '../core';
4+
5+
interface Service {
6+
// eslint-disable-next-line camelcase
7+
unique_name: string;
8+
sid: string;
9+
}
10+
11+
interface Environment {
12+
// eslint-disable-next-line camelcase
13+
unique_name: string;
14+
// eslint-disable-next-line camelcase
15+
build_sid: string;
16+
sid: string;
17+
}
18+
19+
interface Build {}
20+
21+
const realm = testParams.config.region ? `${testParams.config.region}.` : '';
22+
const baseUrl = `https://serverless.${realm}twilio.com/v1`;
23+
const auth = {
24+
username: testParams.secrets.api.accountSid,
25+
password: testParams.secrets.api.authToken,
26+
};
27+
28+
const get = async (uri: string) => {
29+
return axios.get(`${baseUrl}/${uri}`, { auth }).then((resp) => resp.data);
30+
};
31+
32+
const remove = async (uri: string) => {
33+
return axios.delete(`${baseUrl}/${uri}`, { auth });
34+
};
35+
36+
export const getServiceSid = async (): Promise<Service> => {
37+
return get('Services').then((list) => list.services.find((service: Service) => service.unique_name === 'default'));
38+
};
39+
40+
export const deleteEnvironments = async (serviceSid: string): Promise<void> => {
41+
const list = await get(`Services/${serviceSid}/Environments`);
42+
for (const environment of list.environments) {
43+
await remove(`Services/${serviceSid}/Environments/${environment.sid}`);
44+
}
45+
};

0 commit comments

Comments
 (0)