Skip to content

Commit

Permalink
Add tests for snowflake (#561)
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_accountgrant
index_fileformat
index_rolegrants
index_role
index_grantprivilegestorole
index_schema
index_user
index_schemagrant
index_databasegrant
index_task
index_table
index_database
index_tablegrant
  • Loading branch information
VenelinMartinov authored Jun 7, 2024
1 parent 301165b commit 52cce51
Show file tree
Hide file tree
Showing 34 changed files with 544 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 @@ -24,6 +24,14 @@ plugins:
- name: azure
version: "4.7.0"
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
license:
ignore:
# These projects don't have a LICENSE file, but do say mention (in README.md) that
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,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 @@ -432,6 +432,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 @@ -463,6 +463,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 @@ -396,6 +396,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 @@ -10,8 +10,10 @@ replace (

require (
github.com/Snowflake-Labs/terraform-provider-snowflake v0.92.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 @@ -93,6 +95,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.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
Expand Down Expand Up @@ -181,6 +184,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/pelletier/go-toml/v2 v2.1.1 // indirect
Expand Down Expand Up @@ -218,7 +222,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 @@ -262,6 +265,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
18 changes: 18 additions & 0 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
Expand All @@ -1802,6 +1803,12 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
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 @@ -2655,6 +2662,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 @@ -3038,7 +3047,15 @@ github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ
github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0=
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.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
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/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down Expand Up @@ -4324,6 +4341,7 @@ gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/telebot.v3 v3.0.0/go.mod h1:7rExV8/0mDDNu9epSrDm/8j22KLaActH1Tbee6YjzWg=
gopkg.in/telebot.v3 v3.1.2/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko=
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
131 changes: 131 additions & 0 deletions provider/provider_program_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//go:build !go && !nodejs && !python && !dotnet
// +build !go,!nodejs,!python,!dotnet

package snowflake

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 = "snowflake"
const defaultBaselineVersion = "0.50.2"

var programs = []string{
"test-programs/index_accountgrant",
"test-programs/index_fileformat",
"test-programs/index_rolegrants",
"test-programs/index_role",
"test-programs/index_grantprivilegestorole",
"test-programs/index_schema",
"test-programs/index_user",
"test-programs/index_schemagrant",
"test-programs/index_databasegrant",
"test-programs/index_task",
"test-programs/index_table",
"test-programs/index_database",
"test-programs/index_tablegrant",
}

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("SNOWFLAKE_ROLE", "ACCOUNTADMIN")
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_accountgrant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
19 changes: 19 additions & 0 deletions provider/test-programs/index_accountgrant/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: index_accountgrant9XOe6XgqziGU
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/2ab84136-43fd-4765-bf92-3a68c1e9d5d7.zip
outputs:
accountGrantRole: ${exampleAccountGrant.roles[0]}
roleName: ${exampleRole.name}
resources:
exampleAccountGrant:
properties:
privilege: CREATE DATABASE
roles:
- ${exampleRole.name}
type: snowflake:AccountGrant
exampleRole:
type: snowflake:Role
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
42 changes: 42 additions & 0 deletions provider/test-programs/index_database/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: index_databaseK1w012UT8Wct
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/b2e13122-42a0-4df7-8e80-1f75bde32c97.zip
outputs:
snowflakeDatabaseName: ${exampleDatabase.name}
snowflakeRoleName: ${exampleRole.name}
snowflakeSchemaName: ${exampleSchema.name}
snowflakeUserName: ${exampleUser.name}
snowflakeWarehouseName: ${exampleWarehouse.name}
resources:
exampleDatabase:
type: snowflake:Database
exampleGrant:
properties:
databaseName: ${exampleDatabase.name}
roles:
- ${exampleRole.name}
type: snowflake:DatabaseGrant
exampleRole:
type: snowflake:Role
exampleSchema:
properties:
database: ${exampleDatabase.name}
type: snowflake:Schema
exampleUser:
properties:
defaultRole: my_snowflake_role
disabled: false
displayName: Example User
loginName: example_login
type: snowflake:User
exampleWarehouse:
properties:
autoResume: true
autoSuspend: 300
maxClusterCount: 1
warehouseSize: X-SMALL
type: snowflake:Warehouse
2 changes: 2 additions & 0 deletions provider/test-programs/index_databasegrant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
19 changes: 19 additions & 0 deletions provider/test-programs/index_databasegrant/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: index_databasegrantuauVxBfeFZz2
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/d009c937-2a66-4d6d-8d57-992e870e364e.zip
resources:
myDatabase:
type: snowflake:Database
myDatabaseGrant:
properties:
databaseName: ${myDatabase.name}
privilege: USAGE
roles:
- ${myRole.name}
type: snowflake:DatabaseGrant
myRole:
type: snowflake:Role
2 changes: 2 additions & 0 deletions provider/test-programs/index_fileformat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
Loading

0 comments on commit 52cce51

Please sign in to comment.