Skip to content

Commit

Permalink
Regen test docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieMcKinstry committed May 28, 2023
1 parent 625a4f5 commit 8b98abd
Show file tree
Hide file tree
Showing 16 changed files with 501 additions and 23 deletions.
27 changes: 14 additions & 13 deletions pkg/codegen/python/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3011,18 +3011,6 @@ func genPyprojectTOML(tool string,
return "", err
}

// • Set "Authors" and "Maintainers" fields.
// These values are hardcoded to Pulumi's contact information.
// We hardcore this value for now. Later, it will be overridden
// for third-party providers.
// TODO(@Robbie): Third-party provider users can override this field.
contacts := []Contact{{
Name: "The Pulumi Team",
Email: "security@pulumi.com",
}}
schema.Project.Authors = contacts
schema.Project.Maintainers = contacts

// This sets the minimum version of Python.
setPythonRequires(schema, pkg)

Expand Down Expand Up @@ -3119,8 +3107,18 @@ func setDependencies(schema *PyprojectSchema, pkg *schema.Package) error {
// validate.
func ensureValidPulumiVersion(requires map[string]string) (map[string]string, error) {
deps := map[string]string{}
// Special case: if the map is empty, we return just pulumi with no version constraint.
// This is just legacy functionality; there's no obvious reason this should be the case.
if len(requires) == 0 {
result := map[string]string{
"pulumi": "",
}
return result, nil
}
// If the pulumi dep is missing, we require it to fall within
// our major version constraint.
if pulumiDep, ok := requires["pulumi"]; !ok {
deps["pulumi"] = ""
deps["pulumi"] = ">=3.0.0,<4.0.0"
} else {
// Since a value was provided, we check to make sure it's
// within an acceptable version range.
Expand All @@ -3137,6 +3135,9 @@ func ensureValidPulumiVersion(requires map[string]string) (map[string]string, er
if lowerBound.LT(oldestAllowedPulumi) {
return nil, fmt.Errorf("lower version bound must be at least %v", oldestAllowedPulumi)
}
// The provided Pulumi version is valid, so we're copy it into
// the new map.
deps["pulumi"] = pulumiDep
}

// Copy the rest of the dependencies listed into deps.
Expand Down
79 changes: 77 additions & 2 deletions pkg/codegen/python/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,81 @@ Here \\\\N slashes should be escaped but not N
assert.Equal(t, expected, w.String())
}

// This test evaluates the calculateDeps function, which takes a list of
// dependencies, and generates a slice of order pairs, where the first
// item is the name of the dep and the second item is the version constraint.
func TestCalculateDeps(t *testing.T) {
t.Parallel()
type TestCase struct {
// This is the input to the calculate deps function, a list of
// deps provided in the schema.
inputDeps map[string]string
// This is the set of ordered pairs.
expected [][2]string
// calculateDeps can error if the Pulumi version provided is
// invalid. This field is used to check that condition.
expectedErr error
}
cases := []TestCase{{
// Test 1: Give no explicit deps.
inputDeps: map[string]string{},
expected: [][2]string{
// We expect three alphabetized deps,
// with semver and parver formatted differently from Pulumi.
// Pulumi should not have a version.
{"parver>=0.2.1", ""},
{"pulumi", ""},
{"semver>=2.8.1"},
},
}, {
// Test 2: If you only one dep, we expect Pulumi to have a narrower
// constraint than if you had provided no deps.
inputDeps: map[string]string{
"foobar": "7.10.8",
},
expected: [][2]string{
{"foobar", "7.10.8"},
{"parver>=0.2.1", ""},
{"pulumi", ">=3.0.0,<4.0.0"},
{"semver>=2.8.1"},
},
}, {
// Test 3: If you provide pulumi, we expect the constraint to
// be respected.
inputDeps: map[string]string{
"pulumi": ">=3.0.0,<3.50.0",
},
expected: [][2]string{
// We expect three alphabetized deps,
// with semver and parver formatted differently from Pulumi.
{"parver>=0.2.1", ""},
{"pulumi", ">=3.0.0,<3.50.0"},
{"semver>=2.8.1"},
},
}, {
// Test 4: If you provide an illegal pulumi version, we expect an error.
inputDeps: map[string]string{
"pulumi": ">=0.16.0,<4.0.0",
},
expectedErr: fmt.Errorf("lower version bound must be at least %v", oldestAllowedPulumi),
}}

for i, tc := range cases {
tc := tc
name := fmt.Sprintf("CalculateDeps #%d", i+1)
t.Run(name, func(tt *testing.T) {
tt.Parallel()
observedDeps, err := calculateDeps(tc.inputDeps)
assert.Equal(tt, tc.expectedErr, err)
for index := range observedDeps {
observedDep := observedDeps[index]
expectedDep := tc.expected[index]
assert.ElementsMatch(tt, expectedDep, observedDep)
}
})
}
}

// This function tests that setPythonRequires correctly sets the minimum
// Python version when generating pyproject metadata.
func TestPythonRequiresSuccessful(t *testing.T) {
Expand All @@ -285,7 +360,7 @@ func TestPythonRequiresSuccessful(t *testing.T) {
schema.Project = new(Project)

setPythonRequires(schema, &pkg)
observed := schema.Project.RequiresPython
observed := *schema.Project.RequiresPython
assert.Equal(t, expected, observed, "Expected version %s but observed version %s", expected, observed)
}

Expand All @@ -305,6 +380,6 @@ func TestPythonRequiresNotProvided(t *testing.T) {
schema.Project = new(Project)

setPythonRequires(schema, &pkg)
observed := schema.Project.RequiresPython
observed := *schema.Project.RequiresPython
assert.Equal(t, expected, observed, "Expected version %s but observed version %s", expected, observed)
}
1 change: 1 addition & 0 deletions pkg/codegen/testing/test/sdk_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ var PulumiPulumiSDKTests = []*SDKTest{
{
Directory: "simple-schema-pyproject",
Description: "A simple schema that generates a pyproject.toml file",
Skip: codegen.NewStringSet("go/any", "nodejs/any", "dotnet/any"),
},
{
Directory: "simple-resource-schema",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'semver>=2.8.1'
],
zip_safe=False)
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'pulumi-kubernetes>=3.0.0,<4.0.0',
'semver>=2.8.1'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'pulumi-aws>=4.37.1,<5.0.0',
'semver>=2.8.1'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'pulumi-google-native>=0.20.0,<1.0.0',
'semver>=2.8.1'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'pulumi-aws>=4.37.1,<5.0.0',
'semver>=2.8.1'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'pulumi-azure-native>=1.0.0,<2.0.0',
'semver>=2.8.1'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'semver>=2.8.1'
],
zip_safe=False)
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'pulumi-aws>=4.0.0,<5.0.0',
'semver>=2.8.1'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'semver>=2.8.1'
],
zip_safe=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: "example"
title_tag: "example.example"
meta_desc: "This is a test package for pyproject.toml"
layout: api
no_edit_this_page: true
---

<!-- WARNING: this file was generated by test. -->
<!-- Do not edit by hand unless you're certain you know what you are doing! -->

This is a test package for pyproject.toml

<h2 id="resources">Resources</h2>
<ul class="api">
<li><a href="provider/" title="Provider"><span class="api-symbol api-symbol--resource"></span>Provider</a></li>
</ul>

<h2 id="package-details">Package Details</h2>
<dl class="package-details">
<dt>Repository</dt>
<dd><a href="https://github.com/pulumi/pulumi">example pulumi/pulumi</a></dd>
<dt>License</dt>
<dd>MIT</dd>
<dt>Version</dt>
<dd>0.0.1</dd>
</dl>

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"emittedFiles": [
"_index.md",
"provider/_index.md"
]
}

0 comments on commit 8b98abd

Please sign in to comment.