08/10/2023, 6:31 AM
Hi 🙂 I'm not sure if I do the IaC stuff right. But here is what I do in Azure with C# 1. I create a resourcegroup 2. I then create a keyvault 3. I then create an Application Insights 4. I then get the connectionString from ApplicationInsights 5. I use this connectionString to set it as a value to the Keyvault It all works fine. But then I want to add a unit test for it. I mock the calls. But because connectionString is null because it's an output from Application Insights. I can't start the test, it crash becuase connectionString is null. How to solve this? Am I doint it all wrong when I in my stack and C# code reuse values from resources I create and add thoose directly in my IaC code to the keyvault? Shall I do things differently?


08/10/2023, 7:52 PM
If you connecting to something, then it's not a unit: it's at least two units. So you need an integration test. Not a unit test.
And if the thing you're connecting to isn't just one unit (e.g. Applicaiton Insights, which is a full service), then even an integration test is unlikely to be helpful. You'd need an end-to-end system test.
Perhaps you could separate the create-infrastructure bits (1, 2) into one unit and test that. The other bits could go into a separate unit (or units) to be tested outside of your unit tests.


08/15/2023, 10:15 AM
yes. what I want to achieve is a control so that if some one remove infra code then at least a test will fail and say. Whooops... Was this change intentional? if yes, remove the test too. So what I'm testing atm is just the input for the different resources. ex one test that check that application Insights is set and the input is correct. But I'm also using the IaC code as a smarter Automation so I actually get secret values from one keyvault and put it to the one for the service. And in this case I need to call the secretclient from Microsoft so get the value from one secret store to set the config with IaC in the other. In this case there is a bit tricky to mock this client, I haven't found a way to mock dependencies. So in that case the test become an hybird of unit test and integration test, and that I do not like. I need to run the stack mock the calls to even check the if the resources was set. And when run the stack this is when SecretClient also gets called.