Skip to content

Commit

Permalink
Python integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvp committed Dec 14, 2022
1 parent aa95476 commit d684fb0
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/integration/integration_python_test.go
Expand Up @@ -994,3 +994,15 @@ func TestAboutPython(t *testing.T) {
func TestConstructOutputValuesPython(t *testing.T) {
testConstructOutputValues(t, "python", filepath.Join("..", "..", "sdk", "python", "env", "src"))
}

// TestResourceRefsGetResourcePython tests that invoking the built-in 'pulumi:pulumi:getResource' function
// returns resource references for any resource reference in a resource's state.
func TestResourceRefsGetResourcePython(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: filepath.Join("resource_refs_get_resource", "python"),
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
Quick: true,
})
}
@@ -0,0 +1,5 @@
*.pyc
/.pulumi/
/dist/
/*.egg-info
venv/
@@ -0,0 +1,3 @@
name: resource_refs_get_resource_py
description: A program that ensures invoking 'pulumi:pulumi:getResource' returns resource refs
runtime: python
93 changes: 93 additions & 0 deletions tests/integration/resource_refs_get_resource/python/__main__.py
@@ -0,0 +1,93 @@
# Copyright 2016-2022, Pulumi Corporation. All rights reserved.

from typing import Optional

import pulumi


class Child(pulumi.ComponentResource):
@pulumi.input_type
class ChildArgs:
pass

def __init__(
self,
resource_name: str,
message: Optional[str] = None,
opts: Optional[pulumi.ResourceOptions] = None,
):
props = Container.ContainerArgs.__new__(Container.ContainerArgs)
props.__dict__["message"] = message
super().__init__("test:index:Child", resource_name, props, opts)
if opts and opts.urn:
return
self.register_outputs({ "message": message })

@property
@pulumi.getter
def message(self) -> pulumi.Output[str]:
return pulumi.get(self, "message")


class Container(pulumi.ComponentResource):
@pulumi.input_type
class ContainerArgs:
pass

def __init__(
self,
resource_name: str,
child: Optional[Child] = None,
opts: Optional[pulumi.ResourceOptions] = None,
):
props = Container.ContainerArgs.__new__(Container.ContainerArgs)
props.__dict__["child"] = child
super().__init__("test:index:Container", resource_name, props, opts)
if opts and opts.urn:
return
self.register_outputs({ "child": child })

@property
@pulumi.getter
def child(self) -> pulumi.Output[Child]:
return pulumi.get(self, "child")


class Module(pulumi.runtime.ResourceModule):
def version(self):
return "0.0.1"

def construct(self, name: str, typ: str, urn: str) -> pulumi.Resource:
if typ == "test:index:Child":
return Child(name, opts=pulumi.ResourceOptions(urn=urn))
else:
raise Exception(f"unknown resource type {typ}")


pulumi.runtime.register_resource_module("test", "index", Module())


child = Child("mychild", message="hello world!")
container = Container("mycontainer", child=child)


def assert_equal(args):
expected_urn = args["expected_urn"]
actual_urn = args["actual_urn"]
actual_message = args["actual_message"]
assert expected_urn == actual_urn, \
f"expected urn '{expected_urn}' not equal to actual urn '{actual_urn}'"
assert "hello world!" == actual_message, \
f"expected message 'hello world!' not equal to actual message '{actual_message}'"


def round_trip(urn: str):
round_tripped_container = Container("mycontainer", opts=pulumi.ResourceOptions(urn=urn))
pulumi.Output.all(
expected_urn=child.urn,
actual_urn=round_tripped_container.child.urn,
actual_message=round_tripped_container.child.message,
).apply(assert_equal)


container.urn.apply(round_trip)
Empty file.

0 comments on commit d684fb0

Please sign in to comment.