Skip to content

Commit

Permalink
End-2-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailshilkov committed Dec 12, 2024
1 parent 5434ddf commit 626d368
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
57 changes: 57 additions & 0 deletions pkg/pf/tests/autonaming_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package tfbridgetests

import (
"testing"

rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/pulumi/providertest/pulumitest/opttest"
"github.com/stretchr/testify/require"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/pulcheck"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
)

func TestAutonaming(t *testing.T) {
t.Parallel()
provBuilder := providerbuilder.NewProvider(
providerbuilder.NewProviderArgs{
AllResources: []providerbuilder.Resource{
providerbuilder.NewResource(providerbuilder.NewResourceArgs{
ResourceSchema: rschema.Schema{
Attributes: map[string]rschema.Attribute{
"name": rschema.StringAttribute{Optional: true},
},
},
}),
},
})

prov := bridgedProvider(provBuilder)
prov.Resources["testprovider_test"] = &tfbridge.ResourceInfo{
Tok: "testprovider:index:Test",
Fields: map[string]*tfbridge.SchemaInfo{
"name": tfbridge.AutoName("name", 50, "-"),
},
}
program := `
name: test
runtime: yaml
config:
pulumi:autonaming:
value:
pattern: ${project}-${name}
resources:
hello:
type: testprovider:index:Test
outputs:
testOut: ${hello.name}
`
opts := []opttest.Option{
opttest.Env("PULUMI_EXPERIMENTAL", "true"),
}
pt, err := pulcheck.PulCheck(t, prov, program, opts...)
require.NoError(t, err)
res := pt.Up(t)
require.Equal(t, "test-hello", res.Outputs["testOut"].Value)
}
53 changes: 53 additions & 0 deletions pkg/tests/autonaming_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package tests

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pulumi/providertest/pulumitest/opttest"
"github.com/stretchr/testify/require"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/pulcheck"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
)

func TestAutonaming(t *testing.T) {
t.Parallel()
resMap := map[string]*schema.Resource{
"prov_test": {
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
},
},
},
}
tfp := &schema.Provider{ResourcesMap: resMap}
bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp)
bridgedProvider.Resources["prov_test"] = &tfbridge.ResourceInfo{
Tok: "prov:index:Test",
Fields: map[string]*tfbridge.SchemaInfo{
"name": tfbridge.AutoName("name", 50, "-"),
},
}
program := `
name: test
runtime: yaml
config:
pulumi:autonaming:
value:
pattern: ${name}-world
resources:
hello:
type: prov:index:Test
outputs:
testOut: ${hello.name}
`
opts := []opttest.Option{
opttest.Env("PULUMI_EXPERIMENTAL", "true"),
}
pt := pulcheck.PulCheck(t, bridgedProvider, program, opts...)
res := pt.Up(t)
require.Equal(t, "hello-world", res.Outputs["testOut"].Value)
}

0 comments on commit 626d368

Please sign in to comment.