Add Output.All overloads (#4321)

Add Output.All overloads
This commit is contained in:
Mikhail Shilkov 2020-04-07 20:51:05 +02:00 committed by GitHub
parent 00f1433706
commit 1d171dbb74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 6 deletions

View file

@ -23,6 +23,9 @@ CHANGELOG
- Automatic plugin acquisition for Go
[#4297](https://github.com/pulumi/pulumi/pull/4297)
- Add overloads to Output.All in .NET
[#4321](https://github.com/pulumi/pulumi/pull/4321)
## 1.14.0 (2020-04-01)
- Fix error related to side-by-side versions of `@pulumi/pulumi`.
[#4235](https://github.com/pulumi/pulumi/pull/4235)

View file

@ -1,6 +1,7 @@
// Copyright 2016-2019, Pulumi Corporation
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Pulumi.Serialization;
using Xunit;
@ -246,6 +247,52 @@ namespace Pulumi.Tests.Core
Assert.False(data.IsSecret);
Assert.Null(data.Value);
});
[Fact]
public Task AllParamsOutputs()
=> RunInPreview(async () =>
{
var o1 = CreateOutput(1, isKnown: true);
var o2 = CreateOutput(2, isKnown: true);
var o3 = Output.All(o1, o2);
var data = await o3.DataTask.ConfigureAwait(false);
Assert.Equal(new[] { 1, 2 }, data.Value);
});
[Fact]
public Task AllEnumerableOutputs()
=> RunInPreview(async () =>
{
var o1 = CreateOutput(1, isKnown: true);
var o2 = CreateOutput(2, isKnown: true);
var outputs = new[] {o1, o2}.AsEnumerable();
var o3 = Output.All(outputs);
var data = await o3.DataTask.ConfigureAwait(false);
Assert.Equal(new[] { 1, 2 }, data.Value);
});
[Fact]
public Task AllParamsInputs()
=> RunInPreview(async () =>
{
var i1 = (Input<int>)CreateOutput(1, isKnown: true);
var i2 = (Input<int>)CreateOutput(2, isKnown: true);
var o = Output.All(i1, i2);
var data = await o.DataTask.ConfigureAwait(false);
Assert.Equal(new[] { 1, 2 }, data.Value);
});
[Fact]
public Task AllEnumerableInputs()
=> RunInPreview(async () =>
{
var i1 = (Input<int>)CreateOutput(1, isKnown: true);
var i2 = (Input<int>)CreateOutput(2, isKnown: true);
var inputs = new[] {i1, i2}.AsEnumerable();
var o = Output.All(inputs);
var data = await o.DataTask.ConfigureAwait(false);
Assert.Equal(new[] { 1, 2 }, data.Value);
});
}
public class NormalTests

View file

@ -28,20 +28,36 @@ namespace Pulumi
=> Output<T>.CreateSecret(value);
/// <summary>
/// Combines all the <see cref="Input{T}"/> values in <paramref name="inputs"/> and combines
/// them all into a single <see cref="Output{T}"/> with an <see cref="ImmutableArray{T}"/>
/// Combines all the <see cref="Input{T}"/> values in <paramref name="inputs"/>
/// into a single <see cref="Output{T}"/> with an <see cref="ImmutableArray{T}"/>
/// containing all their underlying values. If any of the <see cref="Input{T}"/>s are not
/// known, the final result will be not known. Similarly, if any of the <see
/// cref="Input{T}"/>s are secrets, then the final result will be a secret.
/// </summary>
public static Output<ImmutableArray<T>> All<T>(params Input<T>[] inputs)
=> All(ImmutableArray.CreateRange(inputs));
=> Output<T>.All(ImmutableArray.CreateRange(inputs));
/// <summary>
/// <see cref="All{T}(Input{T}[])"/> for more details.
/// </summary>
public static Output<ImmutableArray<T>> All<T>(ImmutableArray<Input<T>> inputs)
=> Output<T>.All(inputs);
public static Output<ImmutableArray<T>> All<T>(IEnumerable<Input<T>> inputs)
=> Output<T>.All(ImmutableArray.CreateRange(inputs));
/// <summary>
/// Combines all the <see cref="Output{T}"/> values in <paramref name="outputs"/>
/// into a single <see cref="Output{T}"/> with an <see cref="ImmutableArray{T}"/>
/// containing all their underlying values. If any of the <see cref="Output{T}"/>s are not
/// known, the final result will be not known. Similarly, if any of the <see
/// cref="Output{T}"/>s are secrets, then the final result will be a secret.
/// </summary>
public static Output<ImmutableArray<T>> All<T>(params Output<T>[] outputs)
=> All(outputs.AsEnumerable());
/// <summary>
/// <see cref="All{T}(Output{T}[])"/> for more details.
/// </summary>
public static Output<ImmutableArray<T>> All<T>(IEnumerable<Output<T>> outputs)
=> Output<T>.All(ImmutableArray.CreateRange(outputs.Select(o => (Input<T>)o)));
/// <summary>
/// Takes in a <see cref="FormattableString"/> with potential <see cref="Input{T}"/>s or

View file

@ -275,8 +275,10 @@ static Pulumi.Log.Error(string message, Pulumi.Resource resource = null, int? st
static Pulumi.Log.Exception(System.Exception exception, Pulumi.Resource resource = null, int? streamId = null, bool? ephemeral = null) -> void
static Pulumi.Log.Info(string message, Pulumi.Resource resource = null, int? streamId = null, bool? ephemeral = null) -> void
static Pulumi.Log.Warn(string message, Pulumi.Resource resource = null, int? streamId = null, bool? ephemeral = null) -> void
static Pulumi.Output.All<T>(System.Collections.Immutable.ImmutableArray<Pulumi.Input<T>> inputs) -> Pulumi.Output<System.Collections.Immutable.ImmutableArray<T>>
static Pulumi.Output.All<T>(System.Collections.Generic.IEnumerable<Pulumi.Input<T>> inputs) -> Pulumi.Output<System.Collections.Immutable.ImmutableArray<T>>
static Pulumi.Output.All<T>(System.Collections.Generic.IEnumerable<Pulumi.Output<T>> outputs) -> Pulumi.Output<System.Collections.Immutable.ImmutableArray<T>>
static Pulumi.Output.All<T>(params Pulumi.Input<T>[] inputs) -> Pulumi.Output<System.Collections.Immutable.ImmutableArray<T>>
static Pulumi.Output.All<T>(params Pulumi.Output<T>[] outputs) -> Pulumi.Output<System.Collections.Immutable.ImmutableArray<T>>
static Pulumi.Output.Create<T>(System.Threading.Tasks.Task<T> value) -> Pulumi.Output<T>
static Pulumi.Output.Create<T>(T value) -> Pulumi.Output<T>
static Pulumi.Output.CreateSecret<T>(System.Threading.Tasks.Task<T> value) -> Pulumi.Output<T>