github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/go/doc_test.go (about) 1 // Copyright 2016-2020, Pulumi Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Pulling out some of the repeated strings tokens into constants would harm readability, so we just ignore the 16 // goconst linter's warning. 17 // 18 // nolint: lll, goconst 19 package gen 20 21 import ( 22 "fmt" 23 "testing" 24 25 "github.com/pulumi/pulumi/pkg/v3/codegen/schema" 26 "github.com/stretchr/testify/assert" 27 ) 28 29 var testPackageSpec = schema.PackageSpec{ 30 Name: "aws", 31 Version: "0.0.1", 32 Description: "A fake provider package used for testing.", 33 Meta: &schema.MetadataSpec{ 34 ModuleFormat: "(.*)(?:/[^/]*)", 35 }, 36 Types: map[string]schema.ComplexTypeSpec{ 37 "aws:s3/BucketCorsRule:BucketCorsRule": { 38 ObjectTypeSpec: schema.ObjectTypeSpec{ 39 Description: "The resource options object.", 40 Type: "object", 41 Properties: map[string]schema.PropertySpec{ 42 "stringProp": { 43 Description: "A string prop.", 44 TypeSpec: schema.TypeSpec{ 45 Type: "string", 46 }, 47 }, 48 }, 49 }, 50 }, 51 }, 52 Resources: map[string]schema.ResourceSpec{ 53 "aws:s3/bucket:Bucket": { 54 InputProperties: map[string]schema.PropertySpec{ 55 "corsRules": { 56 TypeSpec: schema.TypeSpec{ 57 Ref: "#/types/aws:s3/BucketCorsRule:BucketCorsRule", 58 }, 59 }, 60 }, 61 }, 62 }, 63 } 64 65 func getTestPackage(t *testing.T) *schema.Package { 66 t.Helper() 67 68 pkg, err := schema.ImportSpec(testPackageSpec, nil) 69 assert.NoError(t, err, "could not import the test package spec") 70 return pkg 71 } 72 73 func TestGetDocLinkForPulumiType(t *testing.T) { 74 t.Parallel() 75 76 pkg := getTestPackage(t) 77 d := DocLanguageHelper{} 78 t.Run("Generate_ResourceOptionsLink_Specified", func(t *testing.T) { 79 t.Parallel() 80 81 pkg.Language["go"] = GoPackageInfo{PulumiSDKVersion: 1} 82 expected := "https://pkg.go.dev/github.com/pulumi/pulumi/sdk/go/pulumi?tab=doc#ResourceOption" 83 link := d.GetDocLinkForPulumiType(pkg, "ResourceOption") 84 assert.Equal(t, expected, link) 85 pkg.Language["go"] = nil 86 }) 87 t.Run("Generate_ResourceOptionsLink_Specified", func(t *testing.T) { 88 t.Parallel() 89 90 pkg.Language["go"] = GoPackageInfo{PulumiSDKVersion: 2} 91 expected := "https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v2/go/pulumi?tab=doc#ResourceOption" 92 link := d.GetDocLinkForPulumiType(pkg, "ResourceOption") 93 assert.Equal(t, expected, link) 94 pkg.Language["go"] = nil 95 }) 96 t.Run("Generate_ResourceOptionsLink_Unspecified", func(t *testing.T) { 97 t.Parallel() 98 99 expected := fmt.Sprintf("https://pkg.go.dev/github.com/pulumi/pulumi/sdk/%s/go/pulumi?tab=doc#ResourceOption", pulumiSDKVersion) 100 link := d.GetDocLinkForPulumiType(pkg, "ResourceOption") 101 assert.Equal(t, expected, link) 102 }) 103 } 104 105 func TestGetDocLinkForResourceType(t *testing.T) { 106 t.Parallel() 107 108 pkg := getTestPackage(t) 109 d := DocLanguageHelper{} 110 expected := "https://pkg.go.dev/github.com/pulumi/pulumi-aws/sdk/go/aws/s3?tab=doc#Bucket" 111 link := d.GetDocLinkForResourceType(pkg, "s3", "Bucket") 112 assert.Equal(t, expected, link) 113 }