pulumi/pkg/codegen/dotnet/doc_test.go

99 lines
2.8 KiB
Go
Raw Normal View History

// Copyright 2016-2020, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
sdk/go: Remove 'nolint' directives from package docs Go treats comments that match the following regex as directives. //[a-z0-9]+:[a-z0-9] Comments that are directives don't show in an entity's documentation. https://github.com/golang/go/commit/5a550b695117f07a4f2454039a4871250cd3ed09#diff-f56160fd9fcea272966a8a1d692ad9f49206fdd8dbcbfe384865a98cd9bc2749R165 Our code has `//nolint` directives that now show in the API Reference. This is because these directives are in one of the following forms, which don't get this special treatment. // nolint:foo //nolint: foo This change fixes all such directives found by the regex: `// nolint|//nolint: `. See bottom of commit for command used for the fix. Verification: Here's the output of `go doc` on some entities before and after this change. Before ``` % go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi | head -n8 package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi" nolint: lll, interfacer nolint: lll, interfacer const EnvOrganization = "PULUMI_ORGANIZATION" ... var ErrPlugins = errors.New("pulumi: plugins requested") ``` After ``` % go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi | head -n8 package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi" const EnvOrganization = "PULUMI_ORGANIZATION" ... var ErrPlugins = errors.New("pulumi: plugins requested") func BoolRef(v bool) *bool func Float64Ref(v float64) *float64 func IntRef(v int) *int func IsSecret(o Output) bool ``` Before ``` % go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi URN_ package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi" func URN_(o string) ResourceOption URN_ is an optional URN of a previously-registered resource of this type to read from the engine. nolint: revive ``` After: ``` % go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi URN_ package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi" func URN_(o string) ResourceOption URN_ is an optional URN of a previously-registered resource of this type to read from the engine. ``` Note that golangci-lint offers a 'nolintlint' linter that finds such miuses of nolint, but it also finds other issues so I've deferred that to a follow up PR. Resolves #11785 Related: https://github.com/golangci/golangci-lint/issues/892 [git-generate] FILES=$(mktemp) rg -l '// nolint|//nolint: ' | tee "$FILES" | xargs perl -p -i -e ' s|// nolint|//nolint|g; s|//nolint: |//nolint:|g; ' rg '.go$' < "$FILES" | xargs gofmt -w -s
2023-01-06 00:07:45 +00:00
//nolint:lll
package dotnet
import (
"testing"
"github.com/pulumi/pulumi/pkg/v3/codegen"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/stretchr/testify/assert"
)
var testPackageSpec = schema.PackageSpec{
Name: "aws",
Version: "0.0.1",
Description: "A fake provider package used for testing.",
Meta: &schema.MetadataSpec{
ModuleFormat: "(.*)(?:/[^/]*)",
},
Types: map[string]schema.ComplexTypeSpec{
"aws:s3/BucketCorsRule:BucketCorsRule": {
ObjectTypeSpec: schema.ObjectTypeSpec{
Description: "The resource options object.",
Type: "object",
Properties: map[string]schema.PropertySpec{
"stringProp": {
Description: "A string prop.",
TypeSpec: schema.TypeSpec{
Type: "string",
},
},
},
},
},
},
Resources: map[string]schema.ResourceSpec{
"aws:s3/bucket:Bucket": {
InputProperties: map[string]schema.PropertySpec{
"corsRules": {
TypeSpec: schema.TypeSpec{
Ref: "#/types/aws:s3/BucketCorsRule:BucketCorsRule",
},
},
},
},
},
}
func getTestPackage(t *testing.T) *schema.Package {
t.Helper()
pkg, err := schema.ImportSpec(testPackageSpec, nil)
assert.NoError(t, err, "could not import the test package spec")
return pkg
}
func TestGetDocLinkForResourceType(t *testing.T) {
t.Parallel()
pkg := getTestPackage(t)
d := DocLanguageHelper{}
expected := "/docs/reference/pkg/dotnet/Pulumi.Aws/Pulumi.Aws.S3.Bucket.html"
link := d.GetDocLinkForResourceType(pkg, "doesNotMatter", "Pulumi.Aws.S3.Bucket")
assert.Equal(t, expected, link)
}
func TestGetDocLinkForResourceInputOrOutputType(t *testing.T) {
t.Parallel()
pkg := getTestPackage(t)
namespaces := map[string]string{
"s3": "S3",
}
d := DocLanguageHelper{
Namespaces: namespaces,
}
expected := "/docs/reference/pkg/dotnet/Pulumi.Aws/Pulumi.Aws.S3.Inputs.BucketCorsRuleArgs.html"
// Generate the type string for the property type and use that to generate the doc link.
propertyType := codegen.UnwrapType(pkg.Resources[0].InputProperties[0].Type)
typeString := d.GetLanguageTypeString(pkg, "S3", propertyType, true)
link := d.GetDocLinkForResourceInputOrOutputType(pkg, "doesNotMatter", typeString, true)
assert.Equal(t, expected, link)
}