Stop new projects starting with the word Pulumi

Fixes: #4013

Without this, we are in a situation where we have a cyclic import
This commit is contained in:
stack72 2020-03-05 15:56:01 +02:00
parent 8e87b2b893
commit 3863c6de1a
3 changed files with 63 additions and 2 deletions

View file

@ -4,8 +4,8 @@ CHANGELOG
## HEAD (Unreleased)
* Fix Kubernetes YAML parsing error in .NET.
[#4023](https://github.com/pulumi/pulumi/pull/4023)
---
- Avoid projects beginning with `Pulumi` to stop cyclic imports
[#4013](https://github.com/pulumi/pulumi/pull/4013)
## 1.12.0 (2020-03-04)
- Avoid Configuring providers which are not used during preview.

View file

@ -522,6 +522,12 @@ func ValidateProjectName(s string) error {
return errors.New("A project name may only contain alphanumeric, hyphens, underscores, and periods")
}
// This is needed to stop cyclic imports in DotNet projects
if strings.ToLower(s) == "pulumi" || strings.HasPrefix(strings.ToLower(s), "pulumi.") {
return errors.New("A project name must not be `Pulumi` and must not start with the prefix `Pulumi.` " +
"to avoid collision with standard libraries")
}
return nil
}

View file

@ -241,3 +241,58 @@ func TestRetrieveFileTemplate(t *testing.T) {
})
}
}
func TestProjectNames(t *testing.T) {
tests := []struct {
testName string
projectName string
expectError bool
}{
{
testName: "Correct Project Name",
projectName: "SampleProject",
expectError: false,
},
{
testName: "Project Name with unsupported punctuation",
projectName: "SampleProject!",
expectError: true,
},
{
testName: "Project Name starting with the word Pulumi",
projectName: "PulumiProject",
expectError: false,
},
{
testName: "Project Name greater than 100 characters",
projectName: "cZClTe6xrjgKzH5QS8rFEPqYK1z4bbMeMr6n89n87djq9emSAlznQXXkkCEpBBCaZAFNlCvbfqVcqoifYlfPl11hvekIDjXVIY7m1",
expectError: true,
},
{
testName: "Project Name is Pulumi",
projectName: "Pulumi",
expectError: true,
},
{
testName: "Project Name is Pulumi - mixed case",
projectName: "pUlumI",
expectError: true,
},
{
testName: "Project Name is Pulumi.Test",
projectName: "Pulumi.Test",
expectError: true,
},
}
for _, tt := range tests {
t.Run(tt.testName, func(t *testing.T) {
err := ValidateProjectName(tt.projectName)
if tt.expectError {
assert.Error(t, err)
} else {
assert.Nil(t, err)
}
})
}
}