Skip to content

Commit

Permalink
Create assertion for additional Route53 resources and for KMS resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
JZechy committed Feb 5, 2024
1 parent f3029d6 commit a500359
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CDK.Framework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Testing", "S
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 @@ -66,6 +68,7 @@ Global
{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 @@ -112,5 +115,9 @@ Global
{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
{

}
13 changes: 13 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,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
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";
}
14 changes: 14 additions & 0 deletions Sagittaras.CDK.Testing.Route53/KeySigningKeyProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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; }
}
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
{

}
12 changes: 12 additions & 0 deletions Sagittaras.CDK.Testing/Extensions/TemplateAssertionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ public static void Assert<TResourceAssertion>(this Template template, TResourceA
{
template.HasResource(assertion.Type, assertion.GetResourceDescription());
}

/// <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);
}
}
22 changes: 14 additions & 8 deletions Sagittaras.CDK.Tests.Route53/PublicHostedZoneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Amazon.CDK.Assertions;
using Sagittaras.CDK.Framework.Route53;
using Sagittaras.CDK.Testing.Extensions;
using Sagittaras.CDK.Testing.KMS;
using Sagittaras.CDK.Testing.Route53;
using Xunit;

Expand Down Expand Up @@ -32,8 +33,8 @@ public void Test_BaseFactoryUsage()
Name = Domain
}
});
template.ResourceCountIs("AWS::Route53::HostedZone", 1);
template.ResourceCountIs("AWS::Route53::RecordSet", 0);
template.AssertCount<HostedZoneAssertion>(1);
template.AssertCount<RecordSetAssertion>(0);
}

/// <summary>
Expand All @@ -47,15 +48,20 @@ public void Test_DNSSEC()
.Construct();

Template template = StackTemplate;
template.ResourceCountIs("AWS::KMS::Key", 1);
template.HasResourceProperties("AWS::KMS::Alias", new Dictionary<string, object>
template.AssertCount<KeyAssertion>(1);
template.Assert(new AliasAssertion
{
{ "AliasName", "alias/examplecom-key" }
Properties = new AliasProperties
{
AliasName = "alias/examplecom-key"
}
});

template.HasResourceProperties("AWS::Route53::KeySigningKey", new Dictionary<string, object>
template.Assert(new KeySigningKeyAssertion
{
{ "Status", "ACTIVE" }
Properties = new KeySigningKeyProperties
{
Status = "ACTIVE"
}
});

template.HasResource("AWS::Route53::DNSSEC", new Dictionary<string, object>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<ItemGroup>
<ProjectReference Include="..\Sagittaras.CDK.Framework.Route53\Sagittaras.CDK.Framework.Route53.csproj" />
<ProjectReference Include="..\Sagittaras.CDK.Testing.KMS\Sagittaras.CDK.Testing.KMS.csproj" />
<ProjectReference Include="..\Sagittaras.CDK.Testing.Route53\Sagittaras.CDK.Testing.Route53.csproj" />
<ProjectReference Include="..\Sagittaras.CDK.Tests\Sagittaras.CDK.Tests.csproj" />
</ItemGroup>
Expand Down

0 comments on commit a500359

Please sign in to comment.