Skip to content

Commit 0e27f5e

Browse files
authored
Fix tests (#96)
1 parent 858287b commit 0e27f5e

File tree

17 files changed

+71
-102
lines changed

17 files changed

+71
-102
lines changed

examples/container-schedule/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ provider:
55
# Global Environment variables - used in every functions
66
env:
77
test: test
8-
# the path to the credentials file needs to be absolute
9-
scwToken: <scw-token>
10-
scwProject: <scw-project-id>
11-
# region in which the deployment will happen
12-
scwRegion: fr-par
138

149
plugins:
1510
- serverless-scaleway-functions

examples/container/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ provider:
55
# Global Environment variables - used in every functions
66
env:
77
test: test
8-
# the path to the credentials file needs to be absolute
9-
scwToken: <scw-token>
10-
scwProject: <scw-project-id>
11-
# region in which the deployment will happen
12-
scwRegion: fr-par
138

149
plugins:
1510
- serverless-scaleway-functions

examples/go/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ provider:
66
# Global Environment variables - used in every functions
77
env:
88
test: test
9-
# the path to the credentials file needs to be absolute
10-
scwToken: <scw-token>
11-
scwProject: <scw-project-id>
12-
# region in which the deployment will happen
13-
scwRegion: fr-par
149

1510
plugins:
1611
- serverless-scaleway-functions

examples/go113/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ provider:
66
# Global Environment variables - used in every functions
77
env:
88
test: test
9-
# the path to the credentials file needs to be absolute
10-
scwToken: <scw-token>
11-
scwProject: <scw-project-id>
12-
# region in which the deployment will happen
13-
scwRegion: fr-par
149

1510
plugins:
1611
- serverless-scaleway-functions

examples/multiple/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ provider:
66
# Global Environment variables - used in every functions
77
env:
88
test: test
9-
# the path to the credentials file needs to be absolute
10-
scwToken: <scw-token>
11-
scwProject: <scw-project-id>
12-
# region in which the deployment will happen
13-
scwRegion: fr-par
149

1510
plugins:
1611
- serverless-scaleway-functions

examples/nodejs-es-modules/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ provider:
66
# Global Environment variables - used in every functions
77
env:
88
test: test
9-
# the path to the credentials file needs to be absolute
10-
scwToken: <scw-token>
11-
scwProject: <scw-project-id>
12-
# region in which the deployment will happen
13-
scwRegion: fr-par
149

1510
plugins:
1611
- serverless-scaleway-functions

examples/nodejs-schedule/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ provider:
66
# Global Environment variables - used in every functions
77
env:
88
test: test
9-
# the path to the credentials file needs to be absolute
10-
scwToken: <scw-token>
11-
scwProject: <scw-project-id>
12-
# region in which the deployment will happen
13-
scwRegion: fr-par
149

1510
plugins:
1611
- serverless-scaleway-functions

examples/nodejs/serverless.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ provider:
77
# Global Environment variables - used in every functions
88
env:
99
test: test
10-
# the path to the credentials file needs to be absolute
11-
scwToken: <scw-token>
12-
scwProject: <scw-project-id>
13-
# region in which the deployment will happen
14-
scwRegion: fr-par
1510

1611
plugins:
1712
- serverless-scaleway-functions

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"test:functions": "jest --maxWorkers 5 tests/functions",
1414
"test:containers": "jest --maxWorkers 5 tests/containers",
1515
"test:multi-region": "jest --maxWorkers 5 tests/multi-region",
16+
"test:provider": "jest --maxWorkers 5 tests/provider",
1617
"test:runtimes": "jest --maxWorkers 5 tests/runtimes",
1718
"test:triggers": "jest --maxWorkers 5 tests/triggers",
1819
"coverage": "jest --coverage",

provider/scalewayProvider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class ScalewayProvider {
4848
// On serverless info command we do not want log pollution from authentication.
4949
// This is necessary to use it in an automated environment.
5050
let hideLog = false;
51-
if (this.serverless.configurationInput.service &&
51+
if (this.serverless.configurationInput &&
52+
this.serverless.configurationInput.service &&
5253
this.serverless.configurationInput.service === 'serverlessInfo') {
5354
hideLog = true;
5455
}

tests/containers/containers.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const axios = require('axios');
66
const { expect } = require('chai');
77

88
const { getTmpDirPath, replaceTextInFile } = require('../utils/fs');
9-
const { getServiceName, sleep } = require('../utils/misc');
9+
const { getServiceName, sleep, serverlessDeploy, serverlessRemove} = require('../utils/misc');
1010
const { ContainerApi, RegistryApi } = require('../../shared/api');
1111
const { CONTAINERS_API_URL, REGISTRY_API_URL } = require('../../shared/constants');
1212
const { execSync, execCaptureOutput } = require('../../shared/child-process');
@@ -18,7 +18,7 @@ describe('Service Lifecyle Integration Test', () => {
1818
const tmpDir = getTmpDirPath();
1919
let oldCwd;
2020
let serviceName;
21-
const scwRegion = 'fr-par';
21+
const scwRegion = process.env.SCW_REGION;
2222
const scwProject = process.env.SCW_DEFAULT_PROJECT_ID || process.env.SCW_PROJECT;
2323
const scwToken = process.env.SCW_SECRET_KEY || process.env.SCW_TOKEN;
2424
const apiUrl = `${CONTAINERS_API_URL}/${scwRegion}`;
@@ -46,13 +46,12 @@ describe('Service Lifecyle Integration Test', () => {
4646
replaceTextInFile('serverless.yml', 'scaleway-container', serviceName);
4747
replaceTextInFile('serverless.yml', '<scw-token>', scwToken);
4848
replaceTextInFile('serverless.yml', '<scw-project-id>', scwProject);
49-
replaceTextInFile('serverless.yml', 'scwRegion: fr-par', `scwRegion: ${scwRegion}`);
5049
expect(fs.existsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true);
5150
expect(fs.existsSync(path.join(tmpDir, 'my-container'))).to.be.equal(true);
5251
});
5352

5453
it('should deploy service/container to scaleway', async () => {
55-
execSync(`${serverlessExec} deploy`);
54+
serverlessDeploy();
5655
namespace = await api.getNamespaceFromList(serviceName);
5756
namespace.containers = await api.listContainers(namespace.id);
5857
containerName = namespace.containers[0].name;
@@ -68,7 +67,7 @@ describe('Service Lifecyle Integration Test', () => {
6867

6968
it('should deploy updated service/container to scaleway', () => {
7069
replaceTextInFile('my-container/server.py', 'Hello, World from Scaleway Container !', 'Container successfully updated');
71-
execSync(`${serverlessExec} deploy`);
70+
serverlessDeploy();
7271
});
7372

7473
it('should invoke updated container from scaleway', async () => {
@@ -79,7 +78,7 @@ describe('Service Lifecyle Integration Test', () => {
7978
});
8079

8180
it('should remove service from scaleway', async () => {
82-
execSync(`${serverlessExec} remove`);
81+
serverlessRemove();
8382
try {
8483
await api.getNamespace(namespace.id);
8584
} catch (err) {
@@ -95,7 +94,7 @@ describe('Service Lifecyle Integration Test', () => {
9594
it('should throw error container directory not found', () => {
9695
replaceTextInFile('serverless.yml', 'my-container', 'doesnotexist');
9796
try {
98-
expect(execSync(`${serverlessExec} deploy`)).rejects.toThrow(Error);
97+
expect(serverlessDeploy()).rejects.toThrow(Error);
9998
} catch (err) {
10099
// if not try catch, test would fail
101100
}

tests/functions/functions.test.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { expect } = require('chai');
66
const { expect: jestExpect, it } = require('@jest/globals');
77

88
const { getTmpDirPath, replaceTextInFile } = require('../utils/fs');
9-
const { getServiceName, sleep } = require('../utils/misc');
9+
const { getServiceName, sleep, serverlessDeploy, serverlessRemove} = require('../utils/misc');
1010
const { FunctionApi, RegistryApi } = require('../../shared/api');
1111
const { FUNCTIONS_API_URL, REGISTRY_API_URL } = require('../../shared/constants');
1212
const { execSync, execCaptureOutput } = require('../../shared/child-process');
@@ -23,7 +23,7 @@ describe('Service Lifecyle Integration Test', () => {
2323
const tmpDir = getTmpDirPath();
2424
let oldCwd;
2525
let serviceName;
26-
const scwRegion = 'fr-par';
26+
const scwRegion = process.env.SCW_REGION;
2727
const scwProject = process.env.SCW_DEFAULT_PROJECT_ID || process.env.SCW_PROJECT;
2828
const scwToken = process.env.SCW_SECRET_KEY || process.env.SCW_TOKEN;
2929
const apiUrl = `${FUNCTIONS_API_URL}/${scwRegion}`;
@@ -51,13 +51,12 @@ describe('Service Lifecyle Integration Test', () => {
5151
replaceTextInFile(serverlessFile, 'scaleway-nodeXX', serviceName);
5252
replaceTextInFile(serverlessFile, '<scw-token>', scwToken);
5353
replaceTextInFile(serverlessFile, '<scw-project-id>', scwProject);
54-
replaceTextInFile(serverlessFile, 'scwRegion: fr-par', `scwRegion: ${scwRegion}`);
5554
expect(fs.existsSync(path.join(tmpDir, serverlessFile))).to.be.equal(true);
5655
expect(fs.existsSync(path.join(tmpDir, 'handler.js'))).to.be.equal(true);
5756
});
5857

5958
it('should deploy service to scaleway', async () => {
60-
execSync(`${serverlessExec} deploy`);
59+
serverlessDeploy();
6160
namespace = await api.getNamespaceFromList(serviceName);
6261
namespace.functions = await api.listFunctions(namespace.id);
6362
functionName = namespace.functions[0].name;
@@ -83,7 +82,7 @@ module.exports.handle = (event, context, cb) => {
8382
`;
8483

8584
fs.writeFileSync(path.join(tmpDir, 'handler.js'), newJsHandler);
86-
execSync(`${serverlessExec} deploy`);
85+
serverlessDeploy();
8786
});
8887

8988
it('should create and deploy second function', async () => {
@@ -94,7 +93,7 @@ module.exports.handle = (event, context, cb) => {
9493
// add a 'second' function to serverless.yml
9594
fs.appendFileSync(`${tmpDir}/${serverlessFile}`, appendData);
9695

97-
execSync(`${serverlessExec} deploy`);
96+
serverlessDeploy();
9897
});
9998

10099
it('should invoke first and second function', async () => {
@@ -113,7 +112,7 @@ module.exports.handle = (event, context, cb) => {
113112
replaceTextInFile(serverlessFile, ` handler: handler.handle ${stringIdentifier}`, '');
114113

115114
// redeploy, func 2 should be removed
116-
execSync(`${serverlessExec} deploy`);
115+
serverlessDeploy();
117116

118117
const outputInvoke = execCaptureOutput(serverlessExec, ['invoke', '--function', namespace.functions[0].name]);
119118
expect(outputInvoke).to.be.equal('{"message":"Serverless Update Succeeded"}');
@@ -145,7 +144,7 @@ def handle(event, context):
145144
}
146145
`;
147146
fs.writeFileSync(path.join(tmpDir, 'handler.py'), pythonHandler);
148-
execSync(`${serverlessExec} deploy`);
147+
serverlessDeploy();
149148
});
150149

151150
it('should invoke function with runtime updated from scaleway', async () => {
@@ -156,7 +155,7 @@ def handle(event, context):
156155
});
157156

158157
it('should remove service from scaleway', async () => {
159-
execSync(`${serverlessExec} remove`);
158+
serverlessRemove();
160159
try {
161160
await api.getNamespace(namespace.id);
162161
} catch (err) {
@@ -172,7 +171,7 @@ def handle(event, context):
172171
it('should throw error handler not found', () => {
173172
replaceTextInFile(serverlessFile, 'handler.handle', 'doesnotexist.handle');
174173
try {
175-
expect(execSync(`${serverlessExec} deploy`)).rejects.toThrow(Error);
174+
expect(serverlessDeploy()).rejects.toThrow(Error);
176175
} catch (err) {
177176
// if not try catch, test would fail
178177
}
@@ -182,7 +181,7 @@ def handle(event, context):
182181
it('should throw error runtime does not exist', () => {
183182
replaceTextInFile(serverlessFile, 'node16', 'doesnotexist');
184183
try {
185-
expect(execSync(`${serverlessExec} deploy`)).rejects.toThrow(Error);
184+
expect(serverlessDeploy()).rejects.toThrow(Error);
186185
} catch (err) {
187186
// if not try catch, test would fail
188187
}

tests/multi-region/multi_region.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const axios = require('axios');
66
const { expect } = require('chai');
77
const { execSync } = require('../../shared/child-process');
88
const { getTmpDirPath, replaceTextInFile } = require('../utils/fs');
9-
const { getServiceName, sleep } = require('../utils/misc');
9+
const { getServiceName, sleep, serverlessDeploy, serverlessRemove} = require('../utils/misc');
1010
const { FunctionApi, RegistryApi } = require('../../shared/api');
1111
const { REGISTRY_API_URL, FUNCTIONS_API_URL } = require('../../shared/constants');
1212

@@ -36,14 +36,13 @@ describe.each(regions)(
3636
replaceTextInFile('serverless.yml', 'scaleway-python3', serviceName);
3737
replaceTextInFile('serverless.yml', '<scw-token>', scwToken);
3838
replaceTextInFile('serverless.yml', '<scw-project-id>', scwProject);
39-
replaceTextInFile('serverless.yml', 'scwRegion: fr-par', `scwRegion: ${region}`);
4039
expect(fs.existsSync(path.join(tmpDir, 'serverless.yml'))).to.be.equal(true);
4140
expect(fs.existsSync(path.join(tmpDir, 'handler.py'))).to.be.equal(true);
4241

4342
// deploy function
4443
apiUrl = `${FUNCTIONS_API_URL}/${region}`;
4544
api = new FunctionApi(apiUrl, scwToken);
46-
execSync(`${serverlessExec} deploy`);
45+
serverlessDeploy({ env: { SCW_REGION: region } });
4746
namespace = await api.getNamespaceFromList(serviceName);
4847
namespace.functions = await api.listFunctions(namespace.id);
4948

@@ -55,7 +54,7 @@ describe.each(regions)(
5554
expect(response.data.message).to.be.equal('Hello From Python3 runtime on Serverless Framework and Scaleway Functions');
5655

5756
// delete function
58-
execSync(`${serverlessExec} remove`);
57+
serverlessRemove({ env: { SCW_REGION: region } });
5958
try {
6059
await api.getNamespace(namespace.id);
6160
} catch (err) {

tests/provider/scalewayProvider.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class MockServerless {
2525
};
2626

2727
describe('Scaleway credentials test', () => {
28+
if (process.env.SCW_SECRET_KEY || process.env.SCW_DEFAULT_PROJECT_ID ||
29+
process.env.SCW_TOKEN || process.env.SCW_PROJECT) {
30+
throw new Error("No credentials should be passed in environment variables for this test");
31+
}
32+
2833
this.expectedToken = null;
2934
this.expectedProject = null;
3035

@@ -134,4 +139,3 @@ describe('Scaleway credentials test', () => {
134139
this.checkCreds(options);
135140
});
136141
});
137-

tests/runtimes/runtimes.test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ const axios = require('axios');
66
const { expect } = require('chai');
77
const { execSync } = require('../../shared/child-process');
88
const { getTmpDirPath } = require('../utils/fs');
9-
const { getServiceName, createTestService, sleep } = require('../utils/misc');
9+
const { getServiceName, createTestService, sleep, serverlessDeploy, serverlessRemove} = require('../utils/misc');
1010
const { FunctionApi, RegistryApi, ContainerApi } = require('../../shared/api');
1111
const { FUNCTIONS_API_URL, REGISTRY_API_URL, CONTAINERS_API_URL } = require('../../shared/constants');
1212

13-
const serverlessExec = 'serverless';
14-
15-
const scwRegion = 'nl-ams';
13+
const scwRegion = process.env.SCW_REGION;
1614
const scwProject = process.env.SCW_DEFAULT_PROJECT_ID || process.env.SCW_PROJECT;
1715
const scwToken = process.env.SCW_SECRET_KEY || process.env.SCW_TOKEN;
1816
const functionApiUrl = `${FUNCTIONS_API_URL}/${scwRegion}`;
@@ -59,9 +57,9 @@ describe.each(exampleRepositories)(
5957
process.chdir(tmpDir);
6058
let options = {};
6159
if (runtime === 'secrets') {
62-
options = { env: { PATH: process.env.PATH, ENV_SECRETC: 'valueC', ENV_SECRET3: 'value3' } };
60+
options = { env: { ENV_SECRETC: 'valueC', ENV_SECRET3: 'value3' } };
6361
}
64-
execSync(`${serverlessExec} deploy`, options);
62+
serverlessDeploy(options);
6563
// If runtime is container => get container
6664
if (isContainer) {
6765
api = new ContainerApi(containerApiUrl, scwToken);
@@ -98,7 +96,7 @@ describe.each(exampleRepositories)(
9896

9997
it(`should remove service for runtime ${runtime} from scaleway`, async () => {
10098
process.chdir(tmpDir);
101-
execSync(`${serverlessExec} remove`);
99+
serverlessRemove();
102100
try {
103101
await api.getNamespace(namespace.id);
104102
} catch (err) {

0 commit comments

Comments
 (0)