Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for Route53 module #3

Merged
merged 8 commits into from
Feb 5, 2024
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
.idea/
.idea/
*.DotSettings.user
38 changes: 38 additions & 0 deletions CDK.Framework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2. CDK Modules", "2. CDK Mo
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F2C4D978-97A6-4451-AAD2-16EDCA158D97}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Tests.Route53", "Sagittaras.CDK.Tests.Route53\Sagittaras.CDK.Tests.Route53.csproj", "{64D45D92-6955-42FC-87CD-E1419FB1EA17}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Tests", "Sagittaras.CDK.Tests\Sagittaras.CDK.Tests.csproj", "{E42AD3AD-DBF2-4A25-98CF-E8DA76B356AF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3. Testing", "3. Testing", "{3A01C380-5151-4039-A00C-A33687E00861}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Testing", "Sagittaras.CDK.Testing\Sagittaras.CDK.Testing.csproj", "{D753C559-6F75-4493-A5A3-00CD0727A2DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Testing.Route53", "Sagittaras.CDK.Testing.Route53\Sagittaras.CDK.Testing.Route53.csproj", "{2C4B4454-A145-405E-85BC-F54B56EAC39B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Testing.KMS", "Sagittaras.CDK.Testing.KMS\Sagittaras.CDK.Testing.KMS.csproj", "{FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -51,6 +63,12 @@ Global
{61F8F5CD-30FF-4019-AE9D-E1AD0DA55029} = {506BD5FC-1E9D-47D4-A609-F977EDF69184}
{272BA799-3674-4104-8E01-511E9EDA0198} = {506BD5FC-1E9D-47D4-A609-F977EDF69184}
{C8F37959-BCB7-43DC-9812-A5623E420923} = {506BD5FC-1E9D-47D4-A609-F977EDF69184}
{64D45D92-6955-42FC-87CD-E1419FB1EA17} = {F2C4D978-97A6-4451-AAD2-16EDCA158D97}
{E42AD3AD-DBF2-4A25-98CF-E8DA76B356AF} = {F2C4D978-97A6-4451-AAD2-16EDCA158D97}
{3A01C380-5151-4039-A00C-A33687E00861} = {AEF441A3-E5F9-46D2-82B9-8EE105CC3274}
{D753C559-6F75-4493-A5A3-00CD0727A2DC} = {3A01C380-5151-4039-A00C-A33687E00861}
{2C4B4454-A145-405E-85BC-F54B56EAC39B} = {3A01C380-5151-4039-A00C-A33687E00861}
{FF8FB1E8-9071-470E-A4F3-6C0CD27716F4} = {3A01C380-5151-4039-A00C-A33687E00861}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{940EEEA3-A068-4793-A44A-D2FCE1143E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -81,5 +99,25 @@ Global
{C8F37959-BCB7-43DC-9812-A5623E420923}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8F37959-BCB7-43DC-9812-A5623E420923}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8F37959-BCB7-43DC-9812-A5623E420923}.Release|Any CPU.Build.0 = Release|Any CPU
{64D45D92-6955-42FC-87CD-E1419FB1EA17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64D45D92-6955-42FC-87CD-E1419FB1EA17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64D45D92-6955-42FC-87CD-E1419FB1EA17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64D45D92-6955-42FC-87CD-E1419FB1EA17}.Release|Any CPU.Build.0 = Release|Any CPU
{E42AD3AD-DBF2-4A25-98CF-E8DA76B356AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E42AD3AD-DBF2-4A25-98CF-E8DA76B356AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E42AD3AD-DBF2-4A25-98CF-E8DA76B356AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E42AD3AD-DBF2-4A25-98CF-E8DA76B356AF}.Release|Any CPU.Build.0 = Release|Any CPU
{D753C559-6F75-4493-A5A3-00CD0727A2DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D753C559-6F75-4493-A5A3-00CD0727A2DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D753C559-6F75-4493-A5A3-00CD0727A2DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D753C559-6F75-4493-A5A3-00CD0727A2DC}.Release|Any CPU.Build.0 = Release|Any CPU
{2C4B4454-A145-405E-85BC-F54B56EAC39B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C4B4454-A145-405E-85BC-F54B56EAC39B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C4B4454-A145-405E-85BC-F54B56EAC39B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C4B4454-A145-405E-85BC-F54B56EAC39B}.Release|Any CPU.Build.0 = Release|Any CPU
{FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions Sagittaras.CDK.Testing.KMS/AliasAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.KMS;

/// <summary>
/// Assertion for AWS::KMS::Alias.
/// </summary>
public class AliasAssertion : ResourceAssertion<AliasProperties>
{
public override string Type => "AWS::KMS::Alias";
}
14 changes: 14 additions & 0 deletions Sagittaras.CDK.Testing.KMS/AliasProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.KMS;

/// <summary>
/// Properties for AWS::KMS::Alias.
/// </summary>
public class AliasProperties : ResourceProperties
{
/// <summary>
/// Name of the key alias.
/// </summary>
public string? AliasName { get; set; }
}
11 changes: 11 additions & 0 deletions Sagittaras.CDK.Testing.KMS/KeyAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.KMS;

/// <summary>
/// Assertion for AWS::KMS::Key.
/// </summary>
public class KeyAssertion : ResourceAssertion<KeyProperties>
{
public override string Type => "AWS::KMS::Key";
}
11 changes: 11 additions & 0 deletions Sagittaras.CDK.Testing.KMS/KeyProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.KMS;

/// <summary>
/// Properties for AWS::KMS::Key.
/// </summary>
public class KeyProperties : ResourceProperties
{

}
20 changes: 20 additions & 0 deletions Sagittaras.CDK.Testing.KMS/Sagittaras.CDK.Testing.KMS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.0-preview-01</Version>
<Title>CDK KMS testing library</Title>
<Authors>Sagittaras Games</Authors>
<PackageProjectUrl>https://github.com/sagittaras/cdk.framework</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/sagittaras/cdk.framework/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/sagittaras/cdk.framework</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Sagittaras.CDK.Testing\Sagittaras.CDK.Testing.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions Sagittaras.CDK.Testing.Route53/DnsSecAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Assertion for Aws::Route53::DNSSEC.
/// </summary>
public class DnsSecAssertion : ResourceAssertion<DnsSecProperties>
{
/// <inheritdoc />
public override string Type => "AWS::Route53::DNSSEC";
}
24 changes: 24 additions & 0 deletions Sagittaras.CDK.Testing.Route53/DnsSecDependency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Class defining DNS SEC dependency on Key Signing Key.
/// </summary>
public class DnsSecDependency : ResourceDependency
{
/// <summary>
///
/// </summary>
/// <param name="kskName">Identification of KSK by its name.</param>
public DnsSecDependency(string kskName)
{
With(new KeySigningKeyAssertion
{
Properties = new KeySigningKeyProperties
{
Name = kskName
}
});
}
}
11 changes: 11 additions & 0 deletions Sagittaras.CDK.Testing.Route53/DnsSecProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Properties for AWS::Route53::DNSSEC.
/// </summary>
public class DnsSecProperties : ResourceProperties
{

}
12 changes: 12 additions & 0 deletions Sagittaras.CDK.Testing.Route53/HostedZoneAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Assertion for AWS::Route53::HostedZone.
/// </summary>
public class HostedZoneAssertion : ResourceAssertion<HostedZoneProperties>
{
/// <inheritdoc />
public override string Type => "AWS::Route53::HostedZone";
}
23 changes: 23 additions & 0 deletions Sagittaras.CDK.Testing.Route53/HostedZoneProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Properties describing the Hosted Zone in the CloudFormation template.
/// </summary>
public class HostedZoneProperties : ResourceProperties
{
private string? _name;

/// <summary>
/// Name of the hosted zone.
/// </summary>
/// <remarks>
/// Automatically appends the trailing dot that is generated for CloudFormation template.
/// </remarks>
public string? Name
{
get => _name;
set => _name = value?.TrimEnd('.') + ".";
}
}
12 changes: 12 additions & 0 deletions Sagittaras.CDK.Testing.Route53/KeySigningKeyAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Assertion for AWS::Route53::KeySigningKey.
/// </summary>
public class KeySigningKeyAssertion : ResourceAssertion<KeySigningKeyProperties>
{
/// <inheritdoc />
public override string Type => "AWS::Route53::KeySigningKey";
}
19 changes: 19 additions & 0 deletions Sagittaras.CDK.Testing.Route53/KeySigningKeyProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Properties for AWS::Route53::KeySigningKey.
/// </summary>
public class KeySigningKeyProperties : ResourceProperties
{
/// <summary>
/// Current status of the KSK.
/// </summary>
public string? Status { get; set; }

/// <summary>
/// Name of the KSK.
/// </summary>
public string? Name { get; set; }
}
12 changes: 12 additions & 0 deletions Sagittaras.CDK.Testing.Route53/RecordSetAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Assertion for AWS::Route53::RecordSet.
/// </summary>
public class RecordSetAssertion : ResourceAssertion<RecordSetProperties>
{
/// <inheritdoc />
public override string Type => "AWS::Route53::RecordSet";
}
11 changes: 11 additions & 0 deletions Sagittaras.CDK.Testing.Route53/RecordSetProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Route53;

/// <summary>
/// Properties for AWS::Route53::RecordSet.
/// </summary>
public class RecordSetProperties : ResourceProperties
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.0-preview-01</Version>
<Title>CDK Route53 test library</Title>
<Authors>Sagittaras Games</Authors>
<PackageProjectUrl>https://github.com/sagittaras/cdk.framework</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/sagittaras/cdk.framework/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/sagittaras/cdk.framework</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Sagittaras.CDK.Testing\Sagittaras.CDK.Testing.csproj" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions Sagittaras.CDK.Testing/Extensions/TemplateAssertionExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Amazon.CDK.Assertions;
using Sagittaras.CDK.Testing.Resources;

namespace Sagittaras.CDK.Testing.Extensions;

/// <summary>
/// Extends the assertion template from the CDK by custom assertion methods.
/// </summary>
public static class TemplateAssertionExtension
{
/// <summary>
/// Asserts that the template has a resource with the given description.
/// </summary>
/// <param name="template"></param>
/// <param name="assertion"></param>
/// <typeparam name="TResourceAssertion"></typeparam>
public static void Assert<TResourceAssertion>(this Template template, TResourceAssertion assertion)
where TResourceAssertion : IResourceAssertion
{
template.HasResource(assertion.Type, assertion.GetResourceDescription(template));
}

/// <summary>
/// Asserts that the template has a given number of resources of the given type.
/// </summary>
/// <param name="template"></param>
/// <param name="count"></param>
/// <typeparam name="TResourceAssertion"></typeparam>
public static void AssertCount<TResourceAssertion>(this Template template, int count)
where TResourceAssertion : IResourceAssertion, new()
{
template.ResourceCountIs(new TResourceAssertion().Type, count);
}
}
38 changes: 38 additions & 0 deletions Sagittaras.CDK.Testing/Resources/IResourceAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Amazon.CDK.Assertions;

namespace Sagittaras.CDK.Testing.Resources;

/// <summary>
/// Basic interface describing the assertion for AWS resource.
/// </summary>
public interface IResourceAssertion
{
/// <summary>
/// AWS Resource type.
/// </summary>
string Type { get; }

/// <summary>
/// Maps on which resources the current resource depends on.
/// </summary>
IResourceDependency? DependsOn { get; set; }

/// <summary>
/// Converts the resource description to a dictionary suitable for template assertion.
/// </summary>
/// <returns></returns>
IDictionary<string, object> GetResourceDescription(Template template);
}

/// <summary>
/// Extends the basic resource assertion with properties.
/// </summary>
/// <typeparam name="TProperties">Type of the properties used for the resource.</typeparam>
public interface IResourceAssertion<TProperties> : IResourceAssertion
where TProperties : IResourceProperties, new()
{
/// <summary>
/// Properties that helps to identify the resource.
/// </summary>
TProperties? Properties { get; set; }
}
Loading
Loading