// Copyright 2016-2023, Pulumi Corporation. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Code generated by gen-pux-applyn; DO NOT EDIT. //nolint:lll package pulumix_test import ( "context" "errors" "reflect" "strconv" "testing" "time" "github.com/pulumi/pulumi/sdk/v3/go/internal" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/pulumi/pulumi/sdk/v3/go/pulumix" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestApply_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply[int]( pulumix.Val[int](1), func(i1 int) []string { return []string{ strconv.Itoa(i1), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1"}, val) } func TestApply_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply[int]( pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(1)), }, func(i1 int) []string { return []string{ strconv.Itoa(i1), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApplyErr_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.ApplyErr[int]( pulumix.Val[int](1), func(int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply[int]( o1, func(int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) } func TestApply2_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply2[int, int]( pulumix.Val[int](1), pulumix.Val[int](2), func(i1 int, i2 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1", "2"}, val) } func TestApply2_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply2[int, int]( pulumix.Val[int](1), pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(2)), }, func(i1 int, i2 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApply2Err_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.Apply2Err[int, int]( pulumix.Val[int](1), pulumix.Val[int](2), func(int, int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply2_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o2 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} // Reject the first output. Don't fill the others. giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply2[int, int]( o1, o2, func(int, int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) } func TestApply3_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply3[int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), func(i1 int, i2 int, i3 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1", "2", "3"}, val) } func TestApply3_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply3[int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(3)), }, func(i1 int, i2 int, i3 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApply3Err_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.Apply3Err[int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), func(int, int, int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply3_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o2 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o3 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} // Reject the first output. Don't fill the others. giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply3[int, int, int]( o1, o2, o3, func(int, int, int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) } func TestApply4_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply4[int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), func(i1 int, i2 int, i3 int, i4 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1", "2", "3", "4"}, val) } func TestApply4_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply4[int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(4)), }, func(i1 int, i2 int, i3 int, i4 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApply4Err_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.Apply4Err[int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), func(int, int, int, int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply4_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o2 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o3 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o4 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} // Reject the first output. Don't fill the others. giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply4[int, int, int, int]( o1, o2, o3, o4, func(int, int, int, int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) } func TestApply5_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply5[int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), func(i1 int, i2 int, i3 int, i4 int, i5 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1", "2", "3", "4", "5"}, val) } func TestApply5_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply5[int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(5)), }, func(i1 int, i2 int, i3 int, i4 int, i5 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApply5Err_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.Apply5Err[int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), func(int, int, int, int, int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply5_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o2 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o3 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o4 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o5 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} // Reject the first output. Don't fill the others. giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply5[int, int, int, int, int]( o1, o2, o3, o4, o5, func(int, int, int, int, int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) } func TestApply6_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply6[int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), func(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), strconv.Itoa(i6), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1", "2", "3", "4", "5", "6"}, val) } func TestApply6_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply6[int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(6)), }, func(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), strconv.Itoa(i6), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApply6Err_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.Apply6Err[int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), func(int, int, int, int, int, int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply6_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o2 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o3 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o4 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o5 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o6 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} // Reject the first output. Don't fill the others. giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply6[int, int, int, int, int, int]( o1, o2, o3, o4, o5, o6, func(int, int, int, int, int, int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) } func TestApply7_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply7[int, int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), pulumix.Val[int](7), func(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), strconv.Itoa(i6), strconv.Itoa(i7), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1", "2", "3", "4", "5", "6", "7"}, val) } func TestApply7_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply7[int, int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(7)), }, func(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), strconv.Itoa(i6), strconv.Itoa(i7), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApply7Err_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.Apply7Err[int, int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), pulumix.Val[int](7), func(int, int, int, int, int, int, int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply7_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o2 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o3 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o4 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o5 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o6 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o7 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} // Reject the first output. Don't fill the others. giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply7[int, int, int, int, int, int, int]( o1, o2, o3, o4, o5, o6, o7, func(int, int, int, int, int, int, int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) } func TestApply8_simpleSuccess(t *testing.T) { t.Parallel() out := pulumix.Apply8[int, int, int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), pulumix.Val[int](7), pulumix.Val[int](8), func(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int, i8 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), strconv.Itoa(i6), strconv.Itoa(i7), strconv.Itoa(i8), } }, ) val, known, secret, deps, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, known) assert.False(t, secret) assert.Empty(t, deps) assert.Equal(t, []string{"1", "2", "3", "4", "5", "6", "7", "8"}, val) } func TestApply8_secretValue(t *testing.T) { t.Parallel() out := pulumix.Apply8[int, int, int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), pulumix.Val[int](7), pulumix.Output[int]{ OutputState: internal.GetOutputState(pulumi.ToSecret(8)), }, func(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int, i8 int) []string { return []string{ strconv.Itoa(i1), strconv.Itoa(i2), strconv.Itoa(i3), strconv.Itoa(i4), strconv.Itoa(i5), strconv.Itoa(i6), strconv.Itoa(i7), strconv.Itoa(i8), } }, ) _, _, secret, _, err := internal.AwaitOutput(context.Background(), out) require.NoError(t, err) assert.True(t, secret) } func TestApply8Err_applyError(t *testing.T) { t.Parallel() giveErr := errors.New("great sadness") out := pulumix.Apply8Err[int, int, int, int, int, int, int, int]( pulumix.Val[int](1), pulumix.Val[int](2), pulumix.Val[int](3), pulumix.Val[int](4), pulumix.Val[int](5), pulumix.Val[int](6), pulumix.Val[int](7), pulumix.Val[int](8), func(int, int, int, int, int, int, int, int) (string, error) { return "", giveErr }, ) _, _, _, _, err := internal.AwaitOutput(context.Background(), out) assert.ErrorIs(t, err, giveErr) } func TestApply8_failedOutput(t *testing.T) { t.Parallel() intType := reflect.TypeOf(0) o1 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o2 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o3 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o4 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o5 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o6 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o7 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} o8 := pulumix.Output[int]{OutputState: internal.NewOutputState(nil, intType)} // Reject the first output. Don't fill the others. giveErr := errors.New("great sadness") internal.RejectOutput(o1, giveErr) out := pulumix.Apply8[int, int, int, int, int, int, int, int]( o1, o2, o3, o4, o5, o6, o7, o8, func(int, int, int, int, int, int, int, int) string { t.Errorf("applied function must not be called") return "" }, ) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() _, _, _, _, err := internal.AwaitOutput(ctx, out) assert.ErrorIs(t, err, giveErr) }