|
| 1 | +// Copyright 2026, Pulumi Corporation. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package tests |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/pulumi/pulumi/pkg/v3/resource/plugin" |
| 19 | + "github.com/pulumi/pulumi/pkg/v3/testing/pulumi-test-language/providers" |
| 20 | + "github.com/pulumi/pulumi/sdk/v3/go/common/resource" |
| 21 | + "github.com/stretchr/testify/assert" |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | +) |
| 24 | + |
| 25 | +func init() { |
| 26 | + // Regression test for https://github.com/pulumi/pulumi/issues/23896: a ComponentResource authored inside a |
| 27 | + // component provider must be able to instantiate and use a provider resource from within its constructor. |
| 28 | + LanguageTests["l3-component-provider"] = LanguageTest{ |
| 29 | + Providers: []func() plugin.Provider{ |
| 30 | + func() plugin.Provider { return &providers.ConfigProvider{} }, |
| 31 | + }, |
| 32 | + Runs: []TestRun{ |
| 33 | + { |
| 34 | + Assert: func(l *L, res AssertArgs) { |
| 35 | + err := res.Err |
| 36 | + snap := res.Snap |
| 37 | + changes := res.Changes |
| 38 | + |
| 39 | + RequireStackResource(l, err, changes) |
| 40 | + |
| 41 | + // stack, component, explicit provider, config resource |
| 42 | + require.Len(l, snap.Resources, 4, "expected 4 resources in snapshot") |
| 43 | + |
| 44 | + RequireSingleResource(l, snap.Resources, "pulumi:pulumi:Stack") |
| 45 | + |
| 46 | + component := RequireSingleResource(l, snap.Resources, "components:index:ProviderComponent") |
| 47 | + assert.Equal(l, "myComponent", component.URN.Name()) |
| 48 | + |
| 49 | + provider := RequireSingleResource(l, snap.Resources, "pulumi:providers:config") |
| 50 | + assert.Equal(l, component.URN, provider.Parent, |
| 51 | + "expected explicit provider to be parented to the component") |
| 52 | + |
| 53 | + configRes := RequireSingleResource(l, snap.Resources, "config:index:Resource") |
| 54 | + assert.Equal(l, component.URN, configRes.Parent, |
| 55 | + "expected config resource to be parented to the component") |
| 56 | + assert.Equal(l, string(provider.URN)+"::"+string(provider.ID), configRes.Provider, |
| 57 | + "expected config resource to use the explicit provider") |
| 58 | + |
| 59 | + want := resource.NewPropertyMapFromMap(map[string]any{"text": "hello"}) |
| 60 | + assert.Equal(l, want, configRes.Inputs, "expected inputs to be %v", want) |
| 61 | + wantOut := resource.NewPropertyMapFromMap(map[string]any{"text": ": hello"}) |
| 62 | + assert.Equal(l, wantOut, configRes.Outputs, "expected outputs to be %v", wantOut) |
| 63 | + }, |
| 64 | + }, |
| 65 | + }, |
| 66 | + } |
| 67 | +} |
0 commit comments