Skip to content

Commit

Permalink
Add remaining alias tests for .NET
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailshilkov committed Nov 11, 2019
1 parent 9936e95 commit a1b63e8
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 365 deletions.
6 changes: 3 additions & 3 deletions tests/integration/aliases/aliases_test.go
Expand Up @@ -13,9 +13,9 @@ import (
var dirs = []string{
"rename",
"adopt_into_component",
// "rename_component_and_child",
// "retype_component",
// "rename_component",
"rename_component_and_child",
"retype_component",
"rename_component",
}

// TestNodejsAliases tests a case where a resource's name changes but it provides an `alias`
Expand Down
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>
39 changes: 39 additions & 0 deletions tests/integration/aliases/dotnet/rename_component/step1/Program.cs
@@ -0,0 +1,39 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

using System.Threading.Tasks;
using Pulumi;

class Resource : ComponentResource
{
public Resource(string name, ComponentResourceOptions options = null)
: base("my:module:Resource", name, options)
{
}
}

// Scenario #3 - rename a component (and all it's children)
class ComponentThree : ComponentResource
{
private Resource resource1;
private Resource resource2;

public ComponentThree(string name, ComponentResourceOptions options = null)
: base("my:module:ComponentThree", name, options)
{
// Note that both un-prefixed and parent-name-prefixed child names are supported. For the later, the implicit
// alias inherited from the parent alias will include replacing the name prefix to match the parent alias name.
this.resource1 = new Resource($"{name}-child", new ComponentResourceOptions { Parent = this });
this.resource2 = new Resource("otherchild", new ComponentResourceOptions { Parent = this });
}
}

class Program
{
static Task<int> Main(string[] args)
{
return Deployment.RunAsync(() =>
{
var comp3 = new ComponentThree("comp3");
});
}
}
@@ -0,0 +1,3 @@
name: aliases_rename_component
description: A program that replaces a resource with a new name and alias.
runtime: dotnet
45 changes: 45 additions & 0 deletions tests/integration/aliases/dotnet/rename_component/step2/Program.cs
@@ -0,0 +1,45 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

using System.Threading.Tasks;
using Pulumi;

class Resource : ComponentResource
{
public Resource(string name, ComponentResourceOptions options = null)
: base("my:module:Resource", name, options)
{
}
}

// Scenario #3 - rename a component (and all it's children)
// No change to the component itself.
class ComponentThree : ComponentResource
{
private Resource resource1;
private Resource resource2;

public ComponentThree(string name, ComponentResourceOptions options = null)
: base("my:module:ComponentThree", name, options)
{
// Note that both un-prefixed and parent-name-prefixed child names are supported. For the later, the implicit
// alias inherited from the parent alias will include replacing the name prefix to match the parent alias name.
this.resource1 = new Resource($"{name}-child", new ComponentResourceOptions { Parent = this });
this.resource2 = new Resource("otherchild", new ComponentResourceOptions { Parent = this });
}
}


class Program
{
static Task<int> Main(string[] args)
{
return Deployment.RunAsync(() =>
{
// Applying an alias to the instance successfully renames both the component and the children.
var comp3 = new ComponentThree("newcomp3", new ComponentResourceOptions
{
Aliases = { new Alias { Name = "comp3" } },
});
});
}
}
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>
@@ -0,0 +1,35 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

using System.Threading.Tasks;
using Pulumi;

class Resource : ComponentResource
{
public Resource(string name, ComponentResourceOptions options = null)
: base("my:module:Resource", name, options)
{
}
}

// Scenario #5 - composing #1 and #3 and making both changes at the same time
class ComponentFive : ComponentResource
{
private Resource resource;

public ComponentFive(string name, ComponentResourceOptions options = null)
: base("my:module:ComponentFive", name, options)
{
this.resource = new Resource("otherchild", new ComponentResourceOptions { Parent = this });
}
}

class Program
{
static Task<int> Main(string[] args)
{
return Deployment.RunAsync(() =>
{
var comp5 = new ComponentFive("comp5");
});
}
}
@@ -0,0 +1,3 @@
name: aliases_rename_component_and_child
description: A program that replaces a resource with a new name and alias.
runtime: dotnet
@@ -0,0 +1,42 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

using System.Threading.Tasks;
using Pulumi;

class Resource : ComponentResource
{
public Resource(string name, ComponentResourceOptions options = null)
: base("my:module:Resource", name, options)
{
}
}

// Scenario #5 - composing #1 and #3
class ComponentFive : ComponentResource
{
private Resource resource;

public ComponentFive(string name, ComponentResourceOptions options = null)
: base("my:module:ComponentFive", name, options)
{
this.resource = new Resource("otherchildrenamed", new ComponentResourceOptions
{
Parent = this,
Aliases = { { new Alias { Name = "otherchild", Parent = this } } },
});
}
}

class Program
{
static Task<int> Main(string[] args)
{
return Deployment.RunAsync(() =>
{
var comp5 = new ComponentFive("newcomp5", new ComponentResourceOptions
{
Aliases = { new Alias { Name = "comp5" } },
});
});
}
}
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>
35 changes: 35 additions & 0 deletions tests/integration/aliases/dotnet/retype_component/step1/Program.cs
@@ -0,0 +1,35 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

using System.Threading.Tasks;
using Pulumi;

class Resource : ComponentResource
{
public Resource(string name, ComponentResourceOptions options = null)
: base("my:module:Resource", name, options)
{
}
}

// Scenario #4 - change the type of a component
class ComponentFour : ComponentResource
{
private Resource resource;

public ComponentFour(string name, ComponentResourceOptions options = null)
: base("my:module:ComponentFour", name, options)
{
this.resource = new Resource("otherchild", new ComponentResourceOptions { Parent = this });
}
}

class Program
{
static Task<int> Main(string[] args)
{
return Deployment.RunAsync(() =>
{
var comp4 = new ComponentFour("comp4");
});
}
}
@@ -0,0 +1,3 @@
name: aliases_retype_component
description: A program that replaces a resource with a new name and alias.
runtime: dotnet
41 changes: 41 additions & 0 deletions tests/integration/aliases/dotnet/retype_component/step2/Program.cs
@@ -0,0 +1,41 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

using System.Threading.Tasks;
using Pulumi;

class Resource : ComponentResource
{
public Resource(string name, ComponentResourceOptions options = null)
: base("my:module:Resource", name, options)
{
}
}

// Scenario #4 - change the type of a component
class ComponentFour : ComponentResource
{
private Resource resource;

public ComponentFour(string name, ComponentResourceOptions options = null)
: base("my:differentmodule:ComponentFourWithADifferentTypeName", name, ComponentResourceOptions.Merge(options, new ComponentResourceOptions
{
// Add an alias that references the old type of this resource
// and then make the base() call with the new type of this resource and the added alias.
Aliases = { new Alias { Type = "my:module:ComponentFour" } }
}))
{
// The child resource will also pick up an implicit alias due to the new type of the component it is parented to.
this.resource = new Resource("otherchild", new ComponentResourceOptions { Parent = this });
}
}

class Program
{
static Task<int> Main(string[] args)
{
return Deployment.RunAsync(() =>
{
var comp4 = new ComponentFour("comp4");
});
}
}

0 comments on commit a1b63e8

Please sign in to comment.