in BenchPress/Generators/AzureDeploymentImporter.cs [29:116]
public static IEnumerable<TestMetadata> Import(
string inputFileFullPath,
string outputFolderPath
)
{
var jsonFileContent = "";
if (inputFileFullPath.EndsWith(".bicep"))
{
var tempFileFullPath = Path.GetTempFileName();
var buildArgs = new string[]
{
"build",
inputFileFullPath,
"--outfile",
tempFileFullPath
};
Bicep.Cli.Program.Main(buildArgs).Wait();
jsonFileContent = File.ReadAllText(tempFileFullPath);
var generateParamsArgs = new string[]
{
"generate-params",
inputFileFullPath,
"--outfile",
outputFolderPath + "\\generated"
};
Bicep.Cli.Program.Main(generateParamsArgs).Wait();
File.Delete(tempFileFullPath);
}
else if (inputFileFullPath.EndsWith(".json"))
{
jsonFileContent = File.ReadAllText(inputFileFullPath);
}
else
{
throw new FileFormatException();
}
var parsed = JsonNode.Parse(jsonFileContent)?.AsObject();
if (parsed == null)
{
throw new Exception("Failed to parse json file");
}
var list = new List<TestMetadata>();
foreach (var resource in (JsonArray)parsed["resources"]!)
{
if (resource == null)
{
throw new Exception("Failed to parse json file");
}
var resourceType = resource["type"]?.ToString().Trim();
var resourceName = resource["name"]?.ToString().Trim();
if (resourceName == null || resourceType == null)
{
throw new Exception("Failed to parse json file");
}
resourceName = ResolveParamsAndVariables(resourceName, parsed);
if (resourceName == null)
{
throw new Exception("Failed to parse json file");
}
var extraProperties = GetExtraProperties(resource, parsed);
try
{
list.Add(new TestMetadata(resourceType, resourceName, extraProperties));
}
catch (UnknownResourceTypeException)
{
// ignore
}
}
return list;
}