Skip to content

Commit

Permalink
test(integ): Add tests for SAM_* Environment Variables (aws#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfuss authored Feb 21, 2019
1 parent 2d898d8 commit 7b9fe32
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/integration/local/invoke/test_integrations_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,48 @@ def test_invoke_with_docker_network_of_host(self):

self.assertEquals(return_code, 0)

def test_invoke_with_docker_network_of_host_in_env_var(self):
command_list = self.get_command_list("HelloWorldServerlessFunction",
template_path=self.template_path,
event_path=self.event_path)

env = os.environ.copy()
env["SAM_DOCKER_NETWORK"] = 'non-existing-network'

process = Popen(command_list, stderr=PIPE, env=env)
process.wait()
process_stderr = b"".join(process.stderr.readlines()).strip()

self.assertIn('Not Found ("network non-existing-network not found")', process_stderr.decode('utf-8'))

def test_sam_template_file_env_var_set(self):
command_list = self.get_command_list("HelloWorldFunctionInNonDefaultTemplate", event_path=self.event_path)

self.test_data_path.joinpath("invoke", "sam-template.yaml")
env = os.environ.copy()
env["SAM_TEMPLATE_FILE"] = str(self.test_data_path.joinpath("invoke", "sam-template.yaml"))

process = Popen(command_list, stdout=PIPE, env=env)
process.wait()
process_stdout = b"".join(process.stdout.readlines()).strip()

self.assertEquals(process_stdout.decode('utf-8'), '"Hello world"')

def test_skip_pull_image_in_env_var(self):
docker.from_env().api.pull('lambci/lambda:python3.6')

command_list = self.get_command_list("HelloWorldLambdaFunction",
template_path=self.template_path,
event_path=self.event_path)

env = os.environ.copy()
env["SAM_SKIP_PULL_IMAGE"] = "True"

process = Popen(command_list, stderr=PIPE, env=env)
process.wait()
process_stderr = b"".join(process.stderr.readlines()).strip()
self.assertIn("Requested to skip pulling images", process_stderr.decode('utf-8'))


class TestUsingConfigFiles(InvokeIntegBase):
template = Path("template.yml")
Expand Down Expand Up @@ -502,6 +544,23 @@ def test_caching_two_layers(self):

self.assertEquals(2, len(os.listdir(str(self.layer_cache))))

def test_caching_two_layers_with_layer_cache_env_set(self):

command_list = self.get_command_list("TwoLayerVersionServerlessFunction",
template_path=self.template_path,
no_event=True,
region=self.region,
parameter_overrides=self.layer_utils.parameters_overrides
)

env = os.environ.copy()
env["SAM_LAYER_CACHE_BASEDIR"] = str(self.layer_cache)

process = Popen(command_list, stdout=PIPE, env=env)
process.wait()

self.assertEquals(2, len(os.listdir(str(self.layer_cache))))


@skipIf(SKIP_LAYERS_TESTS,
"Skip layers tests in Travis only")
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/testdata/invoke/sam-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A hello world application.

Resources:
HelloWorldFunctionInNonDefaultTemplate:
Type: AWS::Serverless::Function
Properties:
Handler: main.handler
Runtime: python3.6
CodeUri: .
Timeout: 600

0 comments on commit 7b9fe32

Please sign in to comment.