Skip to content

Commit

Permalink
Add tests for postgresql (#441)
Browse files Browse the repository at this point in the history
pulumi/pulumi-terraform-bridge#1849

This PR adds tests for the following resources:

index_defaultprivileg
index_role
index_schema
index_database
index_grant
  • Loading branch information
VenelinMartinov authored Jun 7, 2024
1 parent d1f8404 commit d53b0bb
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .ci-mgmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ major-version: 3
docker: true
makeTemplate: bridged
team: ecosystem
actions:
preTest:
- name: make upstream
run: |
make upstream
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
pulumiConvert: 1
plugins:
- name: terraform
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v2.5.0
- name: make upstream
run: |
make upstream
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v2.5.0
- name: make upstream
run: |
make upstream
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v2.5.0
- name: make upstream
run: |
make upstream
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/run-acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v2.5.0
- name: make upstream
run: |
make upstream
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
if: matrix.testTarget == 'local'
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
Expand Down
6 changes: 5 additions & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ go 1.21

require (
github.com/cyrilgdn/terraform-provider-postgresql v0.0.0
github.com/pulumi/providertest v0.0.11
github.com/pulumi/pulumi-terraform-bridge/v3 v3.84.0
github.com/pulumi/pulumi/sdk/v3 v3.118.0
github.com/stretchr/testify v1.9.0
)

require (
Expand Down Expand Up @@ -75,6 +77,7 @@ require (
github.com/ettle/strcase v0.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
Expand Down Expand Up @@ -153,6 +156,7 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/natefinch/atomic v1.0.1 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
Expand Down Expand Up @@ -187,7 +191,6 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
Expand Down Expand Up @@ -231,6 +234,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
Expand Down
21 changes: 21 additions & 0 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1392,9 +1392,18 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 h1:Uc+IZ7gYqAf/rSGFplbWBSHaGolEQlNLgMgSE3ccnIQ=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813/go.mod h1:P+oSoE9yhSRvsmYyZsshflcR6ePWYLql6UU1amW13IM=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gkampitakis/ciinfo v0.3.0 h1:gWZlOC2+RYYttL0hBqcoQhM7h1qNkVqvRCV1fOvpAv8=
github.com/gkampitakis/ciinfo v0.3.0/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo=
github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M=
github.com/gkampitakis/go-diff v1.3.2/go.mod h1:LLgOrpqleQe26cte8s36HTWcTmMEur6OPYerdAAS9tk=
github.com/gkampitakis/go-snaps v0.4.9 h1:x6+GEQeYWC+cnLNsHK5uXXgEQADmlH/1EqMrjfXjzk8=
github.com/gkampitakis/go-snaps v0.4.9/go.mod h1:8HW4KX3JKV8M0GSw69CvT+Jqhd1AlBPMPpBfjBI3bdY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
Expand Down Expand Up @@ -1834,6 +1843,8 @@ github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAm
github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
Expand Down Expand Up @@ -2013,6 +2024,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/texttheater/golang-levenshtein v1.0.1 h1:+cRNoVrfiwufQPhoMzB6N0Yf/Mqajr6t1lOv8GyGE2U=
github.com/texttheater/golang-levenshtein v1.0.1/go.mod h1:PYAKrbF5sAiq9wd+H82hs7gNaen0CplQ9uvm6+enD/8=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 h1:X9dsIWPuuEJlPX//UmRKophhOKCGXc46RVIGuttks68=
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7/go.mod h1:UxoP3EypF8JfGEjAII8jx1q8rQyDnX8qdTCs/UQBVIE=
github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o=
Expand Down Expand Up @@ -2430,6 +2449,7 @@ golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -2949,6 +2969,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
Expand Down
127 changes: 127 additions & 0 deletions provider/provider_program_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//go:build !go && !nodejs && !python && !dotnet
// +build !go,!nodejs,!python,!dotnet

package postgresql

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

"github.com/pulumi/providertest"
"github.com/pulumi/providertest/optproviderupgrade"
"github.com/pulumi/providertest/pulumitest"
"github.com/pulumi/providertest/pulumitest/assertpreview"
"github.com/pulumi/providertest/pulumitest/opttest"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
)

const providerName = "postgresql"
const defaultBaselineVersion = "3.11.0"

var programs = []string{
"test-programs/index_defaultprivileg",
"test-programs/index_role",
"test-programs/index_schema",
"test-programs/index_database",
"test-programs/index_grant",
}

func TestUpgradeCoverage(t *testing.T) {
providertest.ReportUpgradeCoverage(t)
}

type UpgradeTestOpts struct {
baselineVersion string
assertFunc func(*testing.T, auto.PreviewResult)
config map[string]string
}

func WithBaselineVersion(baselineVersion string) func(opts *UpgradeTestOpts) {
return func(opts *UpgradeTestOpts) {
opts.baselineVersion = baselineVersion
}
}

func WithAssertFunc(assertFunc func(*testing.T, auto.PreviewResult)) func(opts *UpgradeTestOpts) {
return func(opts *UpgradeTestOpts) {
opts.assertFunc = assertFunc
}
}

func WithConfig(config map[string]string) func(opts *UpgradeTestOpts) {
return func(opts *UpgradeTestOpts) {
opts.config = config
}
}
func testProviderUpgrade(t *testing.T, dir string, opts ...func(*UpgradeTestOpts)) {
options := &UpgradeTestOpts{}
for _, o := range opts {
o(options)
}
testProviderUpgradeWithOpts(t, dir, options.baselineVersion, options.config, options.assertFunc)
}

func testProviderUpgradeWithOpts(
t *testing.T, dir, baselineVersion string, config map[string]string,
assertFunction func(*testing.T, auto.PreviewResult),
) {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without credentials")
}
cwd, err := os.Getwd()
require.NoError(t, err)
if baselineVersion == "" {
baselineVersion = defaultBaselineVersion
}
test := pulumitest.NewPulumiTest(t, dir,
opttest.DownloadProviderVersion(providerName, baselineVersion),
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")),
)
for k, v := range config {
test.SetConfig(k, v)
}
result := providertest.PreviewProviderUpgrade(test, providerName, baselineVersion, optproviderupgrade.DisableAttach())
if assertFunction != nil {
assertFunction(t, result)
} else {
assertpreview.HasNoReplacements(t, result)
}
}

func testProgram(t *testing.T, dir string) {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without credentials")
}
cwd, err := os.Getwd()
require.NoError(t, err)
t.Setenv("PGSSLMODE", "disable")
t.Setenv("PGHOST", "localhost")
t.Setenv("PGPORT", "5432")
t.Setenv("PGUSER", "postgres")
t.Setenv("PGPASSWORD", "password")
test := pulumitest.NewPulumiTest(t, dir,
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")),
opttest.SkipInstall(),
)
test.Up()
}

func TestPrograms(t *testing.T) {
for _, p := range programs {
t.Run(p, func(t *testing.T) {
testProgram(t, p)
})
}
}

func TestProgramsUpgrade(t *testing.T) {
t.Skipf("skip upgrade tests for now as we have not recorded them.")
for _, p := range programs {
t.Run(p, func(t *testing.T) {
testProviderUpgrade(t, p)
})
}
}
2 changes: 2 additions & 0 deletions provider/test-programs/index_database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
10 changes: 10 additions & 0 deletions provider/test-programs/index_database/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: index_databasehcIS2Rdl2J0Y
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/b2352a0e-67a3-41bb-ad99-dbd41ae0c7de.zip
resources:
exampleDatabase:
type: postgresql:Database
2 changes: 2 additions & 0 deletions provider/test-programs/index_defaultprivileg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
35 changes: 35 additions & 0 deletions provider/test-programs/index_defaultprivileg/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: index_defaultprivileg4YV9hyEh2iKw
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/af48269e-444d-4565-92df-8ed8d322846b.zip
outputs:
databaseName: ${myDatabase.name}
roleName: ${myRole.name}
schemaName: ${mySchema.name}
resources:
myDatabase:
type: postgresql:Database
myDefaultPrivileges:
properties:
database: ${myDatabase.name}
objectType: table
owner: ${myRole.name}
privileges:
- SELECT
- INSERT
- UPDATE
- DELETE
role: ${myRole.name}
schema: ${mySchema.name}
type: postgresql:DefaultPrivileges
myRole:
properties:
login: true
type: postgresql:Role
mySchema:
properties:
database: ${myDatabase.name}
type: postgresql:Schema
2 changes: 2 additions & 0 deletions provider/test-programs/index_grant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
29 changes: 29 additions & 0 deletions provider/test-programs/index_grant/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: index_grantwRbbRpiv68pN
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/02e916cb-1a3d-4c16-80db-79c44e98cad8.zip
resources:
my_database:
type: postgresql:Database
my_grant:
properties:
database: ${my_database.name}
objectType: schema
privileges:
- CREATE
- USAGE
role: ${my_role.name}
schema: ${my_schema.name}
type: postgresql:Grant
my_role:
properties:
login: true
type: postgresql:Role
my_schema:
properties:
database: ${my_database.name}
owner: ${my_role.name}
type: postgresql:Schema
2 changes: 2 additions & 0 deletions provider/test-programs/index_role/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
Loading

0 comments on commit d53b0bb

Please sign in to comment.