Hi everyone, does anyone have an example of writin...
# dotnet
r
Hi everyone, does anyone have an example of writing tests for stacks that include calls to a Pulumi Function? Concrete example: I need to write a test for a method that creates an Azure Event Hub connection string by calling the
ListNamespaceKeys
Function, like so:
Copy code
public Output<string> CreateConnectionString(string applicationName, params Union<string, AccessRights>[] accessRights)
{
    var authorisationRule = new NamespaceAuthorizationRule(applicationName, new NamespaceAuthorizationRuleArgs
    {
        AuthorizationRuleName = applicationName,
        Rights = accessRights,
        NamespaceName = _eventHubNamespace.Name,
        ResourceGroupName = ResourceGroupName
    }, CustomResourceOptions);

    return ListNamespaceKeys.Invoke(new ListNamespaceKeysInvokeArgs
    {
        AuthorizationRuleName = authorisationRule.Name,
        NamespaceName = _eventHubNamespace.Name,
        ResourceGroupName = ResourceGroupName
    }, _invokeOptions).Apply(o => Output.CreateSecret(o.PrimaryConnectionString));
}
The Functions pass through
IMocks.CallAsync()
, but the
ListNamespaceKeysResult
type is sealed and the constructor private, and neither anonymous types nor a copy of the
Result
type can be serialised by Pulumi. I feel like I'm missing something here, and the documentation isn't filling in the gap 😕 (For the purposes of the tests, I don't much care about the precise value of the
PrimaryConnectionString
property--i.e., whether or not it's a valid connection string--and certainly don't care about the values of any of the other properties.)
I resolved this issue: it turns out the return type from
IMocks.CallAsync()
should be an
ImmutableDictionary<string, object>
. I've found another one, though 😁 Given the above code sample, what are the names of the Output(s) I need to populate in order for
ListNamespaceKeys.Invoke().Apply()
to return the stubbed
PrimaryConnectionString
value? How do I go about finding this out, even?