Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
lblackstone committed Jul 11, 2022
1 parent 566db9b commit 4167799
Show file tree
Hide file tree
Showing 25 changed files with 1,027 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type CustomResourcePatch struct {

// NewCustomResourcePatch registers a new resource with the given unique name, arguments, and options.
func NewCustomResourcePatch(ctx *pulumi.Context,
name string, args *CustomResourceArgs, opts ...pulumi.ResourceOption) (*CustomResourcePatch, error) {
name string, args *CustomResourcePatchArgs, opts ...pulumi.ResourceOption) (*CustomResourcePatch, error) {
if args == nil {
args = &CustomResourceArgs{}
args = &CustomResourcePatchArgs{}
}

untyped := kubernetes.UntypedArgs{}
Expand Down Expand Up @@ -77,7 +77,7 @@ type customResourcePatchArgs struct {
OtherFields map[string]interface{} `pulumi:""`
}

// The set of arguments for constructing a CustomResource resource.
// The set of arguments for constructing a CustomResourcePatch resource.
type CustomResourcePatchArgs struct {
// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
ApiVersion pulumi.StringInput
Expand Down
6 changes: 3 additions & 3 deletions sdk/go/kubernetes/apiextensions/customResourcePatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type CustomResourcePatch struct {

// NewCustomResourcePatch registers a new resource with the given unique name, arguments, and options.
func NewCustomResourcePatch(ctx *pulumi.Context,
name string, args *CustomResourceArgs, opts ...pulumi.ResourceOption) (*CustomResourcePatch, error) {
name string, args *CustomResourcePatchArgs, opts ...pulumi.ResourceOption) (*CustomResourcePatch, error) {
if args == nil {
args = &CustomResourceArgs{}
args = &CustomResourcePatchArgs{}
}

untyped := kubernetes.UntypedArgs{}
Expand Down Expand Up @@ -77,7 +77,7 @@ type customResourcePatchArgs struct {
OtherFields map[string]interface{} `pulumi:""`
}

// The set of arguments for constructing a CustomResource resource.
// The set of arguments for constructing a CustomResourcePatch resource.
type CustomResourcePatchArgs struct {
// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
ApiVersion pulumi.StringInput
Expand Down
2 changes: 2 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ require (
github.com/hashicorp/go-hclog v1.0.0 // indirect
github.com/pulumi/pulumi-kubernetes/provider/v3 v3.0.0-rc.1
github.com/pulumi/pulumi-kubernetes/sdk/v3 v3.0.0-rc.1
github.com/pulumi/pulumi-random/sdk/v4 v4.8.0
github.com/pulumi/pulumi/pkg/v3 v3.35.3
github.com/pulumi/pulumi/sdk/v3 v3.35.3
github.com/stretchr/testify v1.7.1
helm.sh/helm/v3 v3.9.0
k8s.io/apimachinery v0.24.0
k8s.io/client-go v0.24.0
)
3 changes: 3 additions & 0 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,8 @@ github.com/pulumi/cloud-ready-checks v1.0.1-0.20220105213132-0fbbc00d3335/go.mod
github.com/pulumi/pulumi-java/pkg v0.1.0/go.mod h1:Dw5klQSJCD6hHaHN4BcCoOW+KjC6NafdBtDsy6sY6uc=
github.com/pulumi/pulumi-java/pkg v0.2.0/go.mod h1:LUz8JGS7Lxn2EnPkxFhB6Rap0CwZyHTHmwLQ16NFIhc=
github.com/pulumi/pulumi-java/pkg v0.4.0/go.mod h1:j3qzYXomeNTibPcInXJVdsaBuHYwv0ISmwTgR6q0hU0=
github.com/pulumi/pulumi-random/sdk/v4 v4.8.0 h1:zaSdfNqcaRqKld2jTB+YZIN7O4BsQ2m/AEFx7qNZJUY=
github.com/pulumi/pulumi-random/sdk/v4 v4.8.0/go.mod h1:czSwj+jZnn/VWovMpTLUs/RL/ZS4PFHRdmlXrkvHqeI=
github.com/pulumi/pulumi-yaml v0.3.0/go.mod h1:6pQ0QcQqLYbq+i5vYjir/gDnpCvTkKcHqB5+mt0d3So=
github.com/pulumi/pulumi-yaml v0.5.2/go.mod h1:VTgGg3z1WFYDeiwnq9rS3Y4qAysHiQS3M4X67wqo0RM=
github.com/pulumi/pulumi/pkg/v3 v3.26.0/go.mod h1:L9E+MXe05AbrSmX1GjX3jIrVNpE2RrauKEjME+BNzi4=
Expand All @@ -1342,6 +1344,7 @@ github.com/pulumi/pulumi/sdk/v3 v3.19.0/go.mod h1:AnbQmAhp0ezO/MhcVjqkhvoQnxZ0+7
github.com/pulumi/pulumi/sdk/v3 v3.26.0/go.mod h1:VsxW+TGv2VBLe/MeqsAr9r0zKzK/gbAhFT9QxYr24cY=
github.com/pulumi/pulumi/sdk/v3 v3.28.0/go.mod h1:Oe6AnW5MjJE5X2UJeqeXm1Al7qahdLVhIPeiKuoqxAw=
github.com/pulumi/pulumi/sdk/v3 v3.31.0/go.mod h1:hGo/+AL1L4sPL9Ukd/i5bNFM3WHs3dHcA+GKEW7M3RA=
github.com/pulumi/pulumi/sdk/v3 v3.31.1/go.mod h1:hGo/+AL1L4sPL9Ukd/i5bNFM3WHs3dHcA+GKEW7M3RA=
github.com/pulumi/pulumi/sdk/v3 v3.32.1/go.mod h1:hGo/+AL1L4sPL9Ukd/i5bNFM3WHs3dHcA+GKEW7M3RA=
github.com/pulumi/pulumi/sdk/v3 v3.33.1/go.mod h1:hGo/+AL1L4sPL9Ukd/i5bNFM3WHs3dHcA+GKEW7M3RA=
github.com/pulumi/pulumi/sdk/v3 v3.33.2-0.20220523224435-36cbf572f457/go.mod h1:hGo/+AL1L4sPL9Ukd/i5bNFM3WHs3dHcA+GKEW7M3RA=
Expand Down
26 changes: 25 additions & 1 deletion tests/sdk/dotnet/dotnet_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2021, Pulumi Corporation.
// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -274,3 +274,27 @@ func TestDotnet_Secrets(t *testing.T) {
})
integration.ProgramTest(t, &test)
}

func TestDotnet_ServerSideApply(t *testing.T) {
test := baseOptions.With(integration.ProgramTestOptions{
Dir: "server-side-apply",
ExpectRefreshChanges: true,
OrderedConfig: []integration.ConfigValue{
{
Key: "pulumi:disable-default-providers[0]",
Value: "kubernetes",
Path: true,
},
},
// TODO: Need to support CustomResource.Get to get the required info here.
//ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// // Validate patched CustomResource
// crPatched := stackInfo.Outputs["crPatched"].(map[string]interface{})
// fooV, ok, err := unstructured.NestedString(crPatched, "metadata", "labels", "foo")
// assert.True(t, ok)
// assert.NoError(t, err)
// assert.Equal(t, "foo", fooV)
//},
})
integration.ProgramTest(t, &test)
}
163 changes: 163 additions & 0 deletions tests/sdk/dotnet/server-side-apply/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Copyright 2016-2022, Pulumi Corporation. All rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Pulumi;
using Pulumi.Kubernetes;
using Pulumi.Kubernetes.Core.V1;
using Pulumi.Kubernetes.ApiExtensions;
using Pulumi.Kubernetes.ApiExtensions.V1;
using Pulumi.Kubernetes.Apps.V1;
using Pulumi.Kubernetes.Rbac.V1;
using Pulumi.Kubernetes.Types.Inputs.Core.V1;
using Pulumi.Kubernetes.Types.Inputs.Apps.V1;
using Pulumi.Kubernetes.Types.Inputs.Meta.V1;
using Pulumi.Kubernetes.Types.Inputs.Rbac.V1;
using Pulumi.Kubernetes.Types.Inputs.ApiExtensions.V1;
using Pulumi.Serialization;

/// <summary>
/// Custom resource arguments for the `Test` custom resource.
/// </summary>
class TestArgs : CustomResourceArgs
{
[Input("spec")]
public Input<TestSpecArgs>? Spec { get; set; }

public TestArgs() : base("example.com/v1", "Test")
{
}
}

class TestSpecArgs : ResourceArgs
{
[Input("foo")]
public Input<string>? Foo { get; set; }
}

/// <summary>
/// Custom resource arguments for the `Test` custom resource.
/// </summary>
class TestPatchArgs : CustomResourcePatchArgs
{
[Input("spec")]
public Input<TestSpecArgs>? Spec { get; set; }

public TestPatchArgs() : base("example.com/v1", "Test")
{
}
}

class Program
{
static Task<int> Main(string[] args)
{
return Pulumi.Deployment.RunAsync(() =>
{
var provider = new Provider("test", new ProviderArgs
{
EnableServerSideApply = true,
});
var ns = new Namespace("test", null, new CustomResourceOptions
{
Provider = provider,
});
var crd = new CustomResourceDefinition("crd", new CustomResourceDefinitionArgs
{
Metadata = new ObjectMetaArgs
{
Name = "tests.example.com",
Namespace = ns.Metadata.Apply(metadata => metadata?.Name),
},
Spec = new CustomResourceDefinitionSpecArgs
{
Group = "example.com",
Versions = {
new CustomResourceDefinitionVersionArgs
{
Name = "v1",
Served = true,
Storage = true,
Schema = new CustomResourceValidationArgs
{
OpenAPIV3Schema = new JSONSchemaPropsArgs
{
Type = "object",
Properties = new InputMap<JSONSchemaPropsArgs> {
["spec"] = new JSONSchemaPropsArgs
{
Type = "object",
Properties = new InputMap<JSONSchemaPropsArgs> {
["foo"] = new JSONSchemaPropsArgs
{
Type = "string",
},
},
},
},
},
},
},
},
Scope = "Namespaced",
Names = new CustomResourceDefinitionNamesArgs
{
Plural = "tests",
Singular = "test",
Kind = "Test",
},
},
},
new CustomResourceOptions
{
Provider = provider,
});
var cr = new Pulumi.Kubernetes.ApiExtensions.CustomResource("cr", new TestArgs
{
Metadata = new ObjectMetaArgs
{
Namespace = ns.Metadata.Apply(metadata => metadata.Name),
Name = "foo"
},
Spec = new TestSpecArgs
{
Foo = "bar"
}
}, new CustomResourceOptions
{
DependsOn = { crd },
Provider = provider
});
var crPatch = new Pulumi.Kubernetes.ApiExtensions.CustomResourcePatch("crPatch", new TestPatchArgs
{
Metadata = new ObjectMetaArgs
{
Labels = new InputMap<string> {
["foo"] = "foo",
},
Namespace = ns.Metadata.Apply(metadata => metadata.Name),
Name = "foo"
},
}, new CustomResourceOptions
{
DependsOn = { cr },
Provider = provider
});
// TODO: Get isn't currently supported for CustomResources.
// var crPatched = Pulumi.Kubernetes.ApiExtensions.CustomResource.Get(ns.Metadata.Apply(m => m.Name), "foo");
return new Dictionary<string, object>{
// { "crPatched", crPatched },
};
});
}
}
3 changes: 3 additions & 0 deletions tests/sdk/dotnet/server-side-apply/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: server-side-apply
description: Tests Server-side Apply support
runtime: dotnet
9 changes: 9 additions & 0 deletions tests/sdk/dotnet/server-side-apply/ServerSideApply.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
32 changes: 31 additions & 1 deletion tests/sdk/go/go_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2021, Pulumi Corporation.
// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

var baseOptions = &integration.ProgramTestOptions{
Expand Down Expand Up @@ -301,4 +302,33 @@ func TestGo(t *testing.T) {
})
integration.ProgramTest(t, &options)
})

t.Run("ServerSideApply", func(t *testing.T) {
options := baseOptions.With(integration.ProgramTestOptions{
Dir: filepath.Join(cwd, "server-side-apply"),
ExpectRefreshChanges: true,
OrderedConfig: []integration.ConfigValue{
{
Key: "pulumi:disable-default-providers[0]",
Value: "kubernetes",
Path: true,
},
},
EditDirs: []integration.EditDir{
{
Dir: filepath.Join("server-side-apply", "step2"),
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// Validate patched CustomResource
crPatchedLabels := stackInfo.Outputs["crPatchedLabels"].(map[string]interface{})
fooV, ok, err := unstructured.NestedString(crPatchedLabels, "foo")
assert.True(t, ok)
assert.NoError(t, err)
assert.Equal(t, "foo", fooV)
},
},
},
})
integration.ProgramTest(t, &options)
})
}
3 changes: 3 additions & 0 deletions tests/sdk/go/server-side-apply/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: server-side-apply-test
description: Tests Server-side Apply support
runtime: go
Loading

0 comments on commit 4167799

Please sign in to comment.