-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for config retrieval (#40)
- Loading branch information
1 parent
c9303ce
commit e2c236c
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,8 @@ TODO.md | |
spot/benchmarks/*/workload.json | ||
|
||
spot-env/ | ||
dump/ | ||
|
||
#Unittest Logs | ||
.coverage | ||
|
||
dump/ |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"FunctionName": "string", | ||
"FunctionArn": "string", | ||
"Runtime": "python3.8", | ||
"Role": "string", | ||
"Handler": "string", | ||
"CodeSize": 123, | ||
"Description": "string", | ||
"Timeout": 123, | ||
"MemorySize": 123, | ||
"LastModified": "2022-02-09T21:58:22.000+0000", | ||
"CodeSha256": "string", | ||
"Version": "string", | ||
"VpcConfig": { | ||
"SubnetIds": [ | ||
"string" | ||
], | ||
"SecurityGroupIds": [ | ||
"string" | ||
], | ||
"VpcId": "string" | ||
}, | ||
"DeadLetterConfig": { | ||
"TargetArn": "string" | ||
}, | ||
"Environment": { | ||
"Variables": { | ||
"string": "string" | ||
}, | ||
"Error": { | ||
"ErrorCode": "string", | ||
"Message": "string" | ||
} | ||
}, | ||
"KMSKeyArn": "string", | ||
"TracingConfig": { | ||
"Mode": "Active" | ||
}, | ||
"MasterArn": "string", | ||
"RevisionId": "string", | ||
"Layers": [ | ||
{ | ||
"Arn": "string", | ||
"CodeSize": 123, | ||
"SigningProfileVersionArn": "string", | ||
"SigningJobArn": "string" | ||
} | ||
], | ||
"State": "Active", | ||
"StateReason": "string", | ||
"StateReasonCode": "Idle", | ||
"LastUpdateStatus": "Successful", | ||
"LastUpdateStatusReason": "string", | ||
"LastUpdateStatusReasonCode": "EniLimitExceeded", | ||
"FileSystemConfigs": [ | ||
{ | ||
"Arn": "string", | ||
"LocalMountPath": "string" | ||
} | ||
], | ||
"PackageType": "Zip", | ||
"ImageConfigResponse": { | ||
"ImageConfig": { | ||
"EntryPoint": [ | ||
"string" | ||
], | ||
"Command": [ | ||
"string" | ||
], | ||
"WorkingDirectory": "string" | ||
}, | ||
"Error": { | ||
"ErrorCode": "string", | ||
"Message": "string" | ||
} | ||
}, | ||
"SigningProfileVersionArn": "string", | ||
"SigningJobArn": "string", | ||
"Architectures": [ | ||
"x86_64" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import unittest | ||
import json | ||
from unittest.mock import patch, call | ||
import datetime | ||
|
||
import spot | ||
from spot.configs.aws_config_retriever import AWSConfigRetriever | ||
from spot.db.db import DBClient | ||
|
||
|
||
class TestConfigRetrieval(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.function = "AWSHelloWorld" | ||
self.timestamp = 0 | ||
self.configRetriever = AWSConfigRetriever(self.function, "localhost", 27017) | ||
|
||
@patch.object( | ||
spot.configs.aws_config_retriever.DBClient, "add_new_config_if_changed" | ||
) | ||
@patch("spot.configs.aws_config_retriever.boto3") | ||
def test_get_latest_config(self, mockBoto3, mockDBClient): | ||
sample_config = [] | ||
with open("tests/config_tests/sample_function_configuration.json") as f: | ||
sample_config = json.load(f) | ||
mockBoto3.client( | ||
"lambda" | ||
).get_function_configuration.return_value = sample_config | ||
self.configRetriever.get_latest_config() | ||
|
||
# assert a database call has been made with function add_new_config_if_changed with appropriate variables | ||
date = datetime.datetime.strptime( | ||
sample_config["LastModified"], "%Y-%m-%dT%H:%M:%S.%f+0000" | ||
) | ||
timestamp = str( | ||
(date - datetime.datetime(1970, 1, 1)).total_seconds() * 1000 | ||
) | ||
sample_config["LastModifiedInMs"] = int(timestamp[:-2]) | ||
sample_config["Architectures"] = sample_config["Architectures"][0] | ||
callTemp = call(self.function, "config", sample_config) | ||
mockDBClient.assert_has_calls([callTemp]) | ||
|
||
@patch.object( | ||
spot.configs.aws_config_retriever.DBClient, "get_all_collection_documents" | ||
) | ||
def test_print_configs(self, mockDBClient): | ||
sample_config = [] | ||
with open("tests/config_tests/sample_function_configuration.json") as f: | ||
sample_config = json.load(f) | ||
mockDBClient.get_all_collection_documents.return_value = [sample_config] | ||
self.configRetriever.print_configs() | ||
|
||
# assert a database call to get_all_collection_documents has been made with proper variables | ||
callTemp = call(self.function, "config") | ||
mockDBClient.assert_has_calls([callTemp]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |