public Task <(string?id, object state)> NewRandomId(MockResourceArgs args, ImmutableDictionary <string, object> .Builder outputs) { // We set a mocked hex value for this unit test outputs.Add("hex", "fh3ue3"); return(Task.FromResult((args.Id, (object)outputs))); }
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); // Set the name to resource name if it's not set explicitly in inputs. if (!args.Inputs.ContainsKey("name")) { outputs.Add("name", args.Name); } if (args.Type == "azure:storage/blob: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:storage/account:Account") { // ... set its web endpoint property. // Normally this would be calculated by Azure, so we have to mock it. outputs.Add("primaryWebEndpoint", $"https://{args.Name}.web.core.windows.net"); } // 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))); }
public async Task <(string?id, object state)> NewResourceAsync( MockResourceArgs args) { await Task.Delay(0); return("myID", new Dictionary <string, object>()); }
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); // Default the resource ID to `{name}_id`. if (args.Id == null || args.Id == "") { args.Id = $"{args.Name}_id"; } outputs.Add("id", args.Id); switch (args.Type) { case "random:index/randomId:RandomId": return(NewRandomId(args, outputs)); case "azure-native:resources:ResourceGroup": return(NewResourceGroup(args, outputs)); case "azure-native:storage:StorageAccount": return(NewStorageAccount(args, outputs)); default: return(Task.FromResult((args.Id, (object)outputs))); } }
public Task <(string?id, object state)> NewResourceAsync(MockResourceArgs args) { if (args.Type == "test:DeploymentResourceDependencyGatheringTests:resource") { return(Task.FromResult <(string?, object)>((this.IsPreview ? null : "id", new Dictionary <string, object>()))); } throw new Exception($"Unknown resource {args.Type}"); }
public Task <(string?id, object state)> NewResourceAsync(MockResourceArgs args) { if (args.Type == "mypkg::mockdep") { var dictBuilder = ImmutableDictionary.CreateBuilder <string, Object>(); dictBuilder.Add("mockDepOutput", "mock-dep-output-value"); var result = (object)(dictBuilder.ToImmutableDictionary()); return(Task.FromResult <(string?id, object state)>((id: "mockDep#1", state: result))); } throw new Exception($"NewResourceAsync not implemented for {args.Type}.."); }
public async Task <(string?id, object state)> NewResourceAsync( MockResourceArgs args) { var emptyDict = new Dictionary <string, object>(); (string?, object)empty = ($"i-{Guid.NewGuid()}", emptyDict); await Task.Delay(0); return(args.Type switch { "issue7422::Component" => empty, "issue7422::Resource" => empty, _ => throw new Exception($"Unknown resource {args.Type}") });
public Task <(string?id, object state)> NewResourceAsync(MockResourceArgs args) { switch (args.Type) { case "test:index:resource": case "test:missing:resource": return(Task.FromResult <(string?, object)>((this._isPreview ? null : "id", new Dictionary <string, object>()))); case "test:index:component": case "test:missing:component": return(Task.FromResult <(string?, object)>((null, new Dictionary <string, object>()))); default: throw new Exception($"Unknown resource {args.Type}"); } }
public Task <(string?id, object state)> NewResourceAsync(MockResourceArgs args) { switch (args.Type) { case "aws:ec2/instance:Instance": return(Task.FromResult <(string?, object)>(("i-1234567890abcdef0", new Dictionary <string, object> { { "publicIp", "203.0.113.12" }, }))); case "pkg:index:MyCustom": return(Task.FromResult <(string?, object)>((args.Name + "_id", args.Inputs))); default: throw new Exception($"Unknown resource {args.Type}"); } }
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.Type == "aws:ec2/instance:Instance") { outputs.Add("publicIp", "203.0.113.12"); outputs.Add("publicDns", "ec2-203-0-113-12.compute-1.amazonaws.com"); } // 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))); }
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); // Default the resource ID to `{name}_id`. if (args.Id == null || args.Id == "") { args.Id = $"{args.Name}_id"; } outputs.Add("id", args.Id); switch (args.Type) { case "azure-native:network:VirtualNetwork": return(NewVNet(args, outputs)); default: return(Task.FromResult((args.Id, (object)outputs))); } }
public Task <(string?id, object state)> NewNetworkSecurityGroup(MockResourceArgs args, ImmutableDictionary <string, object> .Builder outputs) { outputs.Add("name", args.Inputs["networkSecurityGroupName"]); return(Task.FromResult((args.Id, (object)outputs))); }
public Task <(string?id, object state)> NewResourceAsync(MockResourceArgs args) =>
private Task <(string?id, object state)> NewVNet(MockResourceArgs args, ImmutableDictionary <string, object> .Builder outputs) { outputs.Add("name", args.Inputs["virtualNetworkName"]); return(Task.FromResult((args.Id, (object)outputs))); }
public Task <(string?id, object state)> NewResourceAsync(MockResourceArgs args) { throw new Exception($"Unknown resource {args.Type}"); }
public Task <(string?id, object state)> NewStorageAccount(MockResourceArgs args, ImmutableDictionary <string, object> .Builder outputs) { outputs.Add("name", args.Inputs["accountName"]); return(Task.FromResult((args.Id, (object)outputs))); }
public Task <(string?id, object state)> NewResourceAsync(MockResourceArgs args) { throw new Exception("NewResourceAsync not implemented.."); }