Skip to content

Commit ef54328

Browse files
authored
Test GetSchema and gen-sdk with the dotnet testprovider (#418)
Change the TestProvider test to also check that GetSchema and gen-sdk works.
1 parent 7255284 commit ef54328

File tree

7 files changed

+63
-31
lines changed

7 files changed

+63
-31
lines changed

integration_tests/integration_dotnet_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"testing"
2828
"time"
2929

30+
"github.com/pulumi/pulumi/pkg/v3/engine"
3031
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
3132
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
3233
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
@@ -530,6 +531,13 @@ func TestProvider(t *testing.T) {
530531
assert.Equal(t, "hello", stack.Outputs["echoB"])
531532
assert.Equal(t, []interface{}{float64(1), "goodbye", true}, stack.Outputs["echoC"])
532533
},
534+
PrePrepareProject: func(info *engine.Projinfo) error {
535+
e := ptesting.NewEnvironment(t)
536+
e.CWD = info.Root
537+
path := info.Proj.Plugins.Providers[0].Path
538+
_, _ = e.RunCommand("pulumi", "package", "gen-sdk", path, "--language", "dotnet")
539+
return nil
540+
},
533541
})
534542
}
535543

integration_tests/provider/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
using System.Collections.Generic;
44
using System.Threading.Tasks;
55
using Pulumi;
6+
using Pulumi.Testprovider;
67

78
class Program
89
{
910
static Task<int> Main(string[] args)
1011
{
1112
return Deployment.RunAsync(() =>
1213
{
13-
var customA = new TestResource("a", new TestResourceArgs { Echo = 42 });
14-
var customB = new TestResource("b", new TestResourceArgs { Echo = "hello" });
15-
var customC = new TestResource("c", new TestResourceArgs { Echo = new object[] { 1, "goodbye", true} });
14+
var customA = new Echo("a", new EchoArgs { Value = 42 });
15+
var customB = new Echo("b", new EchoArgs { Value = "hello" });
16+
var customC = new Echo("c", new EchoArgs { Value = new object[] { 1, "goodbye", true} });
1617

1718
return new Dictionary<string, object?>
1819
{
19-
{ "echoA", customA.Echo },
20-
{ "echoB", customB.Echo },
21-
{ "echoC", customC.Echo },
20+
{ "echoA", customA.Value },
21+
{ "echoB", customB.Value },
22+
{ "echoC", customC.Value },
2223
};
2324
});
2425
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<DefaultItemExcludes>$(DefaultItemExcludes);sdk/**/*.cs</DefaultItemExcludes>
45
<OutputType>Exe</OutputType>
56
<TargetFramework Condition=" '$(TARGET_FRAMEWORK)' != '' ">$(TARGET_FRAMEWORK)</TargetFramework>
67
<TargetFramework Condition=" '$(TARGET_FRAMEWORK)' == '' ">net6.0</TargetFramework>
78
<Nullable>enable</Nullable>
89
</PropertyGroup>
910

11+
<ItemGroup>
12+
<ProjectReference Include="sdk\dotnet\Pulumi.Testprovider.csproj" />
13+
</ItemGroup>
14+
1015
</Project>

integration_tests/provider/TestResource.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

integration_tests/testprovider/TestProvider.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,42 @@ public TestProvider(IHost host) {
1414
this.host = host;
1515
}
1616

17+
public override Task<GetSchemaResponse> GetSchema(GetSchemaRequest request, CancellationToken ct)
18+
{
19+
var schema = """
20+
{
21+
"name": "testprovider",
22+
"version": "1.0.0",
23+
"meta": {
24+
"supportPack": true
25+
},
26+
"resources": {
27+
"testprovider:index:Echo": {
28+
"description": "A test resource that echoes its input.",
29+
"properties": {
30+
"value": {
31+
"$ref": "pulumi.json#/Any",
32+
"description": "Input to echo."
33+
}
34+
},
35+
"inputProperties": {
36+
"value": {
37+
"$ref": "pulumi.json#/Any",
38+
"description": "Input to echo."
39+
}
40+
},
41+
"type": "object"
42+
}
43+
}
44+
}
45+
""";
46+
47+
return Task.FromResult(new GetSchemaResponse()
48+
{
49+
Schema = schema,
50+
});
51+
}
52+
1753
public override Task<CheckResponse> CheckConfig(CheckRequest request, CancellationToken ct)
1854
{
1955
return Task.FromResult(new CheckResponse() { Inputs = request.NewInputs });
@@ -44,10 +80,10 @@ public override Task<CheckResponse> Check(CheckRequest request, CancellationToke
4480
public override Task<DiffResponse> Diff(DiffRequest request, CancellationToken ct)
4581
{
4682
if (request.Type == "testprovider:index:Echo") {
47-
var changes = !request.OldState["echo"].Equals(request.NewInputs["echo"]);
83+
var changes = !request.OldState["value"].Equals(request.NewInputs["value"]);
4884
return Task.FromResult(new DiffResponse() {
4985
Changes = changes,
50-
Replaces = new string[] { "echo" },
86+
Replaces = new string[] { "value" },
5187
});
5288
}
5389
else if (request.Type == "testprovider:index:Random")
@@ -84,7 +120,7 @@ public override Task<CreateResponse> Create(CreateRequest request, CancellationT
84120
{
85121
if (request.Type == "testprovider:index:Echo") {
86122
var outputs = new Dictionary<string, PropertyValue>();
87-
outputs.Add("echo", request.Properties["echo"]);
123+
outputs.Add("value", request.Properties["value"]);
88124

89125
++this.id;
90126
return Task.FromResult(new CreateResponse() {

integration_tests/testprovider/TestProvider.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework Condition=" '$(TARGET_FRAMEWORK)' != '' ">$(TARGET_FRAMEWORK)</TargetFramework>
66
<TargetFramework Condition=" '$(TARGET_FRAMEWORK)' == '' ">net6.0</TargetFramework>
77
<Nullable>enable</Nullable>
8+
<LangVersion>11</LangVersion>
89
</PropertyGroup>
910

1011
<ItemGroup>

pulumi-language-dotnet/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ func (host *dotnetLanguageHost) GetProgramDependencies(
938938
func (host *dotnetLanguageHost) RunPlugin(
939939
req *pulumirpc.RunPluginRequest, server pulumirpc.LanguageRuntime_RunPluginServer,
940940
) error {
941-
logging.V(5).Infof("Attempting to run dotnet plugin in %s", req.Program)
941+
logging.V(5).Infof("Attempting to run dotnet plugin in %s", req.Pwd)
942942

943943
closer, stdout, stderr, err := rpcutil.MakeRunPluginStreams(server, false)
944944
if err != nil {
@@ -965,15 +965,15 @@ func (host *dotnetLanguageHost) RunPlugin(
965965
if req.Info.EntryPoint != "" {
966966
project = filepath.Join(project, req.Info.EntryPoint)
967967
}
968-
args = append(args, "--project", project)
968+
args = append(args, "--project", project, "--")
969969
}
970970

971971
// Add on all the request args to start this plugin
972972
args = append(args, req.Args...)
973973

974974
if logging.V(5) {
975975
commandStr := strings.Join(args, " ")
976-
logging.V(5).Infoln("Language host launching process: ", executable, commandStr)
976+
logging.V(5).Infoln("Language host launching process: ", executable, " ", commandStr)
977977
}
978978

979979
// Now simply spawn a process to execute the requested program, wiring up stdout/stderr directly.

0 commit comments

Comments
 (0)