Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Output.All overloads #4321

Merged
merged 2 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions sdk/dotnet/Pulumi.Tests/Core/OutputTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -246,6 +247,52 @@ public Task ApplyDoesNotPropagateSecretOnUnknownUnknownOutput()
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
Expand Down
26 changes: 21 additions & 5 deletions sdk/dotnet/Pulumi/Core/Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,36 @@ public static Output<T> CreateSecret<T>(Task<T> value)
=> 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
Expand Down
4 changes: 3 additions & 1 deletion sdk/dotnet/Pulumi/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down