How to get environment variables defined in serverless.yml in tests
up vote
2
down vote
favorite
I am using the serverless framework for running lambda functions on AWS.
In my serverless.yml
there are environment variables that are fetched from SSM.
When I write integration tests for the code, I need the code to have the environment variables and I can't find a good way to do this.
I don't want to duplicate all the variables definitions just for the tests, they are already defined in the serverless.yml. Also, some are secrets and I can't commit them to source conrol, so I would have to also repeat them in the ci environment.
Tried using the serverless-jest-plugin
but it is not working and not well maintained.
Ideas I had for solutions:
- Make the tests exec
sls invoke
- this will work but would mean that the code cannot be debugged, I won't know the test coverage, and it will be slow. - Parse the
serverless.yml
myself and export the env variables - possible but rewriting the logic of pulling the SSM variables just for tests seems wrong.
Any ideas?
node.js integration-testing jestjs serverless-framework
add a comment |
up vote
2
down vote
favorite
I am using the serverless framework for running lambda functions on AWS.
In my serverless.yml
there are environment variables that are fetched from SSM.
When I write integration tests for the code, I need the code to have the environment variables and I can't find a good way to do this.
I don't want to duplicate all the variables definitions just for the tests, they are already defined in the serverless.yml. Also, some are secrets and I can't commit them to source conrol, so I would have to also repeat them in the ci environment.
Tried using the serverless-jest-plugin
but it is not working and not well maintained.
Ideas I had for solutions:
- Make the tests exec
sls invoke
- this will work but would mean that the code cannot be debugged, I won't know the test coverage, and it will be slow. - Parse the
serverless.yml
myself and export the env variables - possible but rewriting the logic of pulling the SSM variables just for tests seems wrong.
Any ideas?
node.js integration-testing jestjs serverless-framework
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am using the serverless framework for running lambda functions on AWS.
In my serverless.yml
there are environment variables that are fetched from SSM.
When I write integration tests for the code, I need the code to have the environment variables and I can't find a good way to do this.
I don't want to duplicate all the variables definitions just for the tests, they are already defined in the serverless.yml. Also, some are secrets and I can't commit them to source conrol, so I would have to also repeat them in the ci environment.
Tried using the serverless-jest-plugin
but it is not working and not well maintained.
Ideas I had for solutions:
- Make the tests exec
sls invoke
- this will work but would mean that the code cannot be debugged, I won't know the test coverage, and it will be slow. - Parse the
serverless.yml
myself and export the env variables - possible but rewriting the logic of pulling the SSM variables just for tests seems wrong.
Any ideas?
node.js integration-testing jestjs serverless-framework
I am using the serverless framework for running lambda functions on AWS.
In my serverless.yml
there are environment variables that are fetched from SSM.
When I write integration tests for the code, I need the code to have the environment variables and I can't find a good way to do this.
I don't want to duplicate all the variables definitions just for the tests, they are already defined in the serverless.yml. Also, some are secrets and I can't commit them to source conrol, so I would have to also repeat them in the ci environment.
Tried using the serverless-jest-plugin
but it is not working and not well maintained.
Ideas I had for solutions:
- Make the tests exec
sls invoke
- this will work but would mean that the code cannot be debugged, I won't know the test coverage, and it will be slow. - Parse the
serverless.yml
myself and export the env variables - possible but rewriting the logic of pulling the SSM variables just for tests seems wrong.
Any ideas?
node.js integration-testing jestjs serverless-framework
node.js integration-testing jestjs serverless-framework
edited yesterday
asked Nov 9 at 20:15
brafdlog
1,4741108
1,4741108
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Are you looking to do mocked unit tests, or something more like integration tests?
In the first case, you don't need real values for the environment variables. Mock your database, or whatever requires environment variables set. This is actually the preferable way because the tests will run super quickly with proper mocks.
If you are actually looking to go with end-to-end/integration kind of approach, then you would do something like sls invoke
, but from jest using javascript. So, like regular network calls to your deployed api.
Also, I would recommend not to store keys in serverless.yml
. Try the secret: $env:MY_SECRET
syntax instead (https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-environment-variables), and use environment variables instead. If you have a ci/cd build server, you can store your secrets there.
Im am looking for a solution for integration tests. Updated the question to clarify. Thanks
– brafdlog
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Are you looking to do mocked unit tests, or something more like integration tests?
In the first case, you don't need real values for the environment variables. Mock your database, or whatever requires environment variables set. This is actually the preferable way because the tests will run super quickly with proper mocks.
If you are actually looking to go with end-to-end/integration kind of approach, then you would do something like sls invoke
, but from jest using javascript. So, like regular network calls to your deployed api.
Also, I would recommend not to store keys in serverless.yml
. Try the secret: $env:MY_SECRET
syntax instead (https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-environment-variables), and use environment variables instead. If you have a ci/cd build server, you can store your secrets there.
Im am looking for a solution for integration tests. Updated the question to clarify. Thanks
– brafdlog
yesterday
add a comment |
up vote
0
down vote
Are you looking to do mocked unit tests, or something more like integration tests?
In the first case, you don't need real values for the environment variables. Mock your database, or whatever requires environment variables set. This is actually the preferable way because the tests will run super quickly with proper mocks.
If you are actually looking to go with end-to-end/integration kind of approach, then you would do something like sls invoke
, but from jest using javascript. So, like regular network calls to your deployed api.
Also, I would recommend not to store keys in serverless.yml
. Try the secret: $env:MY_SECRET
syntax instead (https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-environment-variables), and use environment variables instead. If you have a ci/cd build server, you can store your secrets there.
Im am looking for a solution for integration tests. Updated the question to clarify. Thanks
– brafdlog
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
Are you looking to do mocked unit tests, or something more like integration tests?
In the first case, you don't need real values for the environment variables. Mock your database, or whatever requires environment variables set. This is actually the preferable way because the tests will run super quickly with proper mocks.
If you are actually looking to go with end-to-end/integration kind of approach, then you would do something like sls invoke
, but from jest using javascript. So, like regular network calls to your deployed api.
Also, I would recommend not to store keys in serverless.yml
. Try the secret: $env:MY_SECRET
syntax instead (https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-environment-variables), and use environment variables instead. If you have a ci/cd build server, you can store your secrets there.
Are you looking to do mocked unit tests, or something more like integration tests?
In the first case, you don't need real values for the environment variables. Mock your database, or whatever requires environment variables set. This is actually the preferable way because the tests will run super quickly with proper mocks.
If you are actually looking to go with end-to-end/integration kind of approach, then you would do something like sls invoke
, but from jest using javascript. So, like regular network calls to your deployed api.
Also, I would recommend not to store keys in serverless.yml
. Try the secret: $env:MY_SECRET
syntax instead (https://serverless.com/framework/docs/providers/aws/guide/variables#referencing-environment-variables), and use environment variables instead. If you have a ci/cd build server, you can store your secrets there.
answered Nov 9 at 22:12
Herman Starikov
727315
727315
Im am looking for a solution for integration tests. Updated the question to clarify. Thanks
– brafdlog
yesterday
add a comment |
Im am looking for a solution for integration tests. Updated the question to clarify. Thanks
– brafdlog
yesterday
Im am looking for a solution for integration tests. Updated the question to clarify. Thanks
– brafdlog
yesterday
Im am looking for a solution for integration tests. Updated the question to clarify. Thanks
– brafdlog
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232729%2fhow-to-get-environment-variables-defined-in-serverless-yml-in-tests%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password