Skip to content

Commit

Permalink
feat: Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 committed Jun 13, 2024
1 parent 51079ed commit 937bb61
Show file tree
Hide file tree
Showing 13 changed files with 840 additions and 4 deletions.
19 changes: 18 additions & 1 deletion plugins/aws/fix_plugin_aws/resource/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,20 @@ class AwsBackupProtectedResource(AwsResource):
)
reference_kinds: ClassVar[ModelReference] = {
"predecessors": {"default": ["aws_backup_vault", "aws_backup_recovery_point"]},
"successors": {"default": ["aws_s3_bucket", "aws_ec2_instance", "aws_ec2_volume","aws_rds_cluster","aws_rds_instance","aws_dynamodb_table","aws_dynamodb_global_table","aws_efs_file_system", "aws_redshift_cluster", "aws_cloudformation_stack"]},
"successors": {
"default": [
"aws_s3_bucket",
"aws_ec2_instance",
"aws_ec2_volume",
"aws_rds_cluster",
"aws_rds_instance",
"aws_dynamodb_table",
"aws_dynamodb_global_table",
"aws_efs_file_system",
"aws_redshift_cluster",
"aws_cloudformation_stack",
]
},
}
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("backup", "list-protected-resources", "Results")
mapping: ClassVar[Dict[str, Bender]] = {
Expand Down Expand Up @@ -349,6 +362,10 @@ class AwsBackupRecoveryPoint(AwsResource):
resource_name: Optional[str] = field(default=None, metadata={"description": "This is the non-unique name of the resource that belongs to the specified backup."}) # fmt: skip
vault_type: Optional[str] = field(default=None, metadata={"description": "This is the type of vault in which the described recovery point is stored."}) # fmt: skip

@classmethod
def service_name(cls) -> Optional[str]:
return service_name

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
if backup_vault_name := self.backup_vault_name:
builder.add_edge(self, reverse=True, clazz=AwsBackupVault, name=backup_vault_name)
Expand Down
8 changes: 5 additions & 3 deletions plugins/aws/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ def count_kind(clazz: Type[AwsResource]) -> int:
return count

for resource in all_resources:
assert count_kind(resource) > 0, "No instances of {} found".format(resource.__name__)
if resource.api_spec is None:
continue
assert count_kind(resource) > 0, f"No instances of {resource.__name__} found"

# make sure all threads have been joined
assert len(threading.enumerate()) == 1
# ensure the correct number of nodes and edges
assert count_kind(AwsResource) == 225
assert len(account_collector.graph.edges) == 515
assert count_kind(AwsResource) == 255
assert len(account_collector.graph.edges) == 572
assert len(account_collector.graph.deferred_edges) == 2
for node in account_collector.graph.nodes:
if isinstance(node, AwsRegion):
Expand Down
113 changes: 113 additions & 0 deletions plugins/aws/test/resources/files/backup/list-backup-jobs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"BackupJobs": [
{
"AccountId": "foo",
"BackupJobId": "foo",
"BackupVaultName": "foo",
"BackupVaultArn": "foo",
"RecoveryPointArn": "foo",
"ResourceArn": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"CompletionDate": "2024-06-13T12:28:55Z",
"State": "PENDING",
"StatusMessage": "foo",
"PercentDone": "foo",
"BackupSizeInBytes": 123,
"IamRoleArn": "foo",
"CreatedBy": {
"BackupPlanId": "foo",
"BackupPlanArn": "foo",
"BackupPlanVersion": "foo",
"BackupRuleId": "foo"
},
"ExpectedCompletionDate": "2024-06-13T12:28:55Z",
"StartBy": "2024-06-13T12:28:55Z",
"ResourceType": "foo",
"BytesTransferred": 123,
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
},
"BackupType": "foo",
"ParentJobId": "foo",
"IsParent": true,
"ResourceName": "foo",
"InitiationDate": "2024-06-13T12:28:55Z",
"MessageCategory": "foo"
},
{
"AccountId": "foo",
"BackupJobId": "foo",
"BackupVaultName": "foo",
"BackupVaultArn": "foo",
"RecoveryPointArn": "foo",
"ResourceArn": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"CompletionDate": "2024-06-13T12:28:55Z",
"State": "PENDING",
"StatusMessage": "foo",
"PercentDone": "foo",
"BackupSizeInBytes": 123,
"IamRoleArn": "foo",
"CreatedBy": {
"BackupPlanId": "foo",
"BackupPlanArn": "foo",
"BackupPlanVersion": "foo",
"BackupRuleId": "foo"
},
"ExpectedCompletionDate": "2024-06-13T12:28:55Z",
"StartBy": "2024-06-13T12:28:55Z",
"ResourceType": "foo",
"BytesTransferred": 123,
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
},
"BackupType": "foo",
"ParentJobId": "foo",
"IsParent": true,
"ResourceName": "foo",
"InitiationDate": "2024-06-13T12:28:55Z",
"MessageCategory": "foo"
},
{
"AccountId": "foo",
"BackupJobId": "foo",
"BackupVaultName": "foo",
"BackupVaultArn": "foo",
"RecoveryPointArn": "foo",
"ResourceArn": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"CompletionDate": "2024-06-13T12:28:55Z",
"State": "PENDING",
"StatusMessage": "foo",
"PercentDone": "foo",
"BackupSizeInBytes": 123,
"IamRoleArn": "foo",
"CreatedBy": {
"BackupPlanId": "foo",
"BackupPlanArn": "foo",
"BackupPlanVersion": "foo",
"BackupRuleId": "foo"
},
"ExpectedCompletionDate": "2024-06-13T12:28:55Z",
"StartBy": "2024-06-13T12:28:55Z",
"ResourceType": "foo",
"BytesTransferred": 123,
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
},
"BackupType": "foo",
"ParentJobId": "foo",
"IsParent": true,
"ResourceName": "foo",
"InitiationDate": "2024-06-13T12:28:55Z",
"MessageCategory": "foo"
}
],
"NextToken": "foo"
}
113 changes: 113 additions & 0 deletions plugins/aws/test/resources/files/backup/list-backup-plans.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"NextToken": "foo",
"BackupPlansList": [
{
"BackupPlanArn": "foo",
"BackupPlanId": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"DeletionDate": "2024-06-13T12:28:55Z",
"VersionId": "foo",
"BackupPlanName": "foo",
"CreatorRequestId": "foo",
"LastExecutionDate": "2024-06-13T12:28:55Z",
"AdvancedBackupSettings": [
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
},
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
},
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
}
]
},
{
"BackupPlanArn": "foo",
"BackupPlanId": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"DeletionDate": "2024-06-13T12:28:55Z",
"VersionId": "foo",
"BackupPlanName": "foo",
"CreatorRequestId": "foo",
"LastExecutionDate": "2024-06-13T12:28:55Z",
"AdvancedBackupSettings": [
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
},
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
},
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
}
]
},
{
"BackupPlanArn": "foo",
"BackupPlanId": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"DeletionDate": "2024-06-13T12:28:55Z",
"VersionId": "foo",
"BackupPlanName": "foo",
"CreatorRequestId": "foo",
"LastExecutionDate": "2024-06-13T12:28:55Z",
"AdvancedBackupSettings": [
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
},
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
},
{
"ResourceType": "foo",
"BackupOptions": {
"0": "foo",
"1": "foo",
"2": "foo"
}
}
]
}
]
}
41 changes: 41 additions & 0 deletions plugins/aws/test/resources/files/backup/list-backup-vaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"BackupVaultList": [
{
"BackupVaultName": "foo",
"BackupVaultArn": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"EncryptionKeyArn": "foo",
"CreatorRequestId": "foo",
"NumberOfRecoveryPoints": 123,
"Locked": true,
"MinRetentionDays": 123,
"MaxRetentionDays": 123,
"LockDate": "2024-06-13T12:28:55Z"
},
{
"BackupVaultName": "foo",
"BackupVaultArn": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"EncryptionKeyArn": "foo",
"CreatorRequestId": "foo",
"NumberOfRecoveryPoints": 123,
"Locked": true,
"MinRetentionDays": 123,
"MaxRetentionDays": 123,
"LockDate": "2024-06-13T12:28:55Z"
},
{
"BackupVaultName": "foo",
"BackupVaultArn": "foo",
"CreationDate": "2024-06-13T12:28:55Z",
"EncryptionKeyArn": "foo",
"CreatorRequestId": "foo",
"NumberOfRecoveryPoints": 123,
"Locked": true,
"MinRetentionDays": 123,
"MaxRetentionDays": 123,
"LockDate": "2024-06-13T12:28:55Z"
}
],
"NextToken": "foo"
}
Loading

0 comments on commit 937bb61

Please sign in to comment.