Skip to content

Commit

Permalink
Updating all packages at the same time and pinning the broken @aws-cd… (
Browse files Browse the repository at this point in the history
#2025)

…k/cloud-assembly-schema
  • Loading branch information
rshade authored Feb 20, 2025
1 parent a49210d commit 8cd9c93
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 39 deletions.
5 changes: 3 additions & 2 deletions aws-ts-nextjs/demoapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"tailwindcss": "3.4.17",
"typescript": "5.1.6"
"typescript": "5.1.6",
"@aws-cdk/cloud-assembly-schema": "40.0.7"
},
"devDependencies": {
"sst": "3.9.8",
"aws-cdk-lib": "2.179.0",
"constructs": "10.4.2"
}
}
}
39 changes: 22 additions & 17 deletions testing-unit-cs-mocks/Testing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,51 @@ class Mocks : IMocks
public Task<(string? id, object state)> NewResourceAsync(MockResourceArgs args)
{
var outputs = ImmutableDictionary.CreateBuilder<string, object>();

// Forward all input parameters as resource outputs, so that we could test them.
outputs.AddRange(args.Inputs);

if (args.Inputs != null)
{
outputs.AddRange(args.Inputs);
}

// Set the name to resource name if it's not set explicitly in inputs.
if (!args.Inputs.ContainsKey("name"))
if (args.Inputs?.ContainsKey("name") != true && args.Name != null)
{
outputs.Add("name", args.Name);

}

if (args.Type == "azure-native:storage:Blob")
{
// Assets can't directly go through the engine.
// We don't need them in the test, so blank out the property for now.
outputs.Remove("source");
}

// For a Storage Account...
if (args.Type == "azure-native:storage:StorageAccount")
if (args.Type == "azure-native:storage:StorageAccount" && args.Name != null)
{
// ... set its web endpoint property.
// Normally this would be calculated by Azure, so we have to mock it.
outputs.Add("primaryEndpoints", new Dictionary<string, string>
{
{ "web", $"https://{args.Name}.web.core.windows.net" },
}.ToImmutableDictionary());
// Normally this would be calculated by Azure, so we have to mock it.
var endpoints = new Dictionary<string, string>
{
{ "web", $"https://{args.Name}.web.core.windows.net" }
};
outputs.Add("primaryEndpoints", endpoints.ToImmutableDictionary());
}

// Default the resource ID to `{name}_id`.
// We could also format it as `/subscription/abc/resourceGroups/xyz/...` if that was important for tests.
args.Id ??= $"{args.Name}_id";
return Task.FromResult((args.Id, (object)outputs));
args.Id ??= args.Name != null ? $"{args.Name}_id" : "unknown_id";
return Task.FromResult((args.Id, (object)outputs.ToImmutable()));
}

public Task<object> CallAsync(MockCallArgs args)
{
// We don't use this method in this particular test suite.
// Default to returning whatever we got as input.
return Task.FromResult((object)args.Args);
}
}

public static class TestingExtensions
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion testing-unit-fs-mocks/UnitTestingFs.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="8.0.1" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
Expand Down
57 changes: 38 additions & 19 deletions testing-unit-fs-mocks/WebsiteStackTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace UnitTesting

open System
open System.Collections.Immutable
open System.Collections.Generic
open System.Threading.Tasks
open NUnit.Framework
open Pulumi
Expand All @@ -14,52 +15,70 @@ open FluentAssertions

[<TestFixture>]
type WebserverStackTests() =
let runTest(): ImmutableArray<Resource> =
let runTest () : ImmutableArray<Resource> =
let options = new TestOptions(IsPreview = Nullable<bool> false)

Deployment.TestAsync<WebsiteStack>(new Mocks(), options)
|> Async.AwaitTask
|> Async.RunSynchronously
let getValue(output: Output<'a>): 'a =

let getValue (output: Output<'a>) : 'a =
let tcs = new TaskCompletionSource<'a>()
output.Apply(fun v -> tcs.SetResult(v); v) |> ignore

output.Apply(fun v ->
tcs.SetResult(v)
v)
|> ignore

tcs.Task.Result

[<Test>]
member this.SingleResourceGroupExists() =
let resources = runTest()
let resources = runTest ()

let resourceGroupCount = resources.OfType<ResourceGroup>() |> Seq.length
resourceGroupCount.Should().Be(1, "a single resource group is expected") |> ignore

(resourceGroupCount :> obj).Should().Be(1, "a single resource group is expected")
|> ignore

[<Test>]
member this.ResourceGroupHasEnvironmentTag() =
let resources = runTest()
let resources = runTest ()
let resourceGroup = resources.OfType<ResourceGroup>() |> Seq.head

let tags = getValue resourceGroup.Tags
tags.Should().NotBeNull("Tags must be defined") |> ignore
tags.Should().ContainKey("Environment", null) |> ignore

(tags :> obj).Should().NotBeNull("Tags must be defined")
|> ignore

(tags :> System.Collections.Generic.IDictionary<string, string>).Should().ContainKey("Environment", null)
|> ignore

[<Test>]
member this.StorageAccountBelongsToResourceGroup() =
let resources = runTest()
let resources = runTest ()
let storageAccount = resources.OfType<Account>() |> Seq.tryHead |> Option.toObj
storageAccount.Should().NotBeNull("Storage account not found") |> ignore


(storageAccount :> obj).Should().NotBeNull("Storage account not found")
|> ignore

let resourceGroupName = getValue storageAccount.ResourceGroupName
resourceGroupName.Should().Be("www-prod-rg", null) |> ignore
(resourceGroupName :> obj).Should().Be("www-prod-rg", null) |> ignore

[<Test>]
member this.UploadsTwoFiles() =
let resources = runTest()
let resources = runTest ()
let filesCount = resources.OfType<Blob>() |> Seq.length
filesCount.Should().Be(2, "Should have uploaded files from `wwwroot`") |> ignore


(filesCount :> obj).Should().Be(2, "Should have uploaded files from `wwwroot`")
|> ignore

[<Test>]
member this.StackExportsWebsiteUrl() =
let resources = runTest()
let resources = runTest ()
let stack = resources.OfType<WebsiteStack>() |> Seq.head

let endpoint = getValue stack.Endpoint
endpoint.Should().Be("https://wwwprodsa.web.core.windows.net", null) |> ignore

(endpoint :> obj).Should().Be("https://wwwprodsa.web.core.windows.net", null)
|> ignore

0 comments on commit 8cd9c93

Please sign in to comment.