Skip to content

Commit

Permalink
chore: Adjust integration tests after moving to separate package (#2115)
Browse files Browse the repository at this point in the history
* Expose SDK errors

* Add comment for client exec removal

* Move accessor methods to production code

* Expose ValidObjectIdentifier function

* Move findOne to internal SDK package

* Export random functions in SDK

* Fix cyclic dependency

* Fix generator templates

* Delegate random to sdk exported ones

* Use exported random helpers in integration tests

* Move random helpers to internal package

* Clean random files a bit

* Rename internal packages

* Remove random from integration tests package

* Update comment

* Add options for random helpers

* Fix generator templates

* Rename random helper functions

* Adjust tests

* Fix after review

* Bump x/net dep

* Fix build
  • Loading branch information
sfc-gh-asawicki authored Oct 12, 2023
1 parent f5d4aeb commit 3f528a8
Show file tree
Hide file tree
Showing 91 changed files with 907 additions and 950 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ require (
github.com/zclconf/go-cty v1.14.0 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.16.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos=
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
10 changes: 5 additions & 5 deletions pkg/sdk/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ type AccountRename struct {
}

func (opts *AccountRename) validate() error {
if !validObjectidentifier(opts.Name) {
if !ValidObjectIdentifier(opts.Name) {
return fmt.Errorf("Name must be set")
}
if !validObjectidentifier(opts.NewName) {
if !ValidObjectIdentifier(opts.NewName) {
return fmt.Errorf("NewName must be set")
}
return nil
Expand All @@ -252,7 +252,7 @@ type AccountDrop struct {
}

func (opts *AccountDrop) validate() error {
if !validObjectidentifier(opts.Name) {
if !ValidObjectIdentifier(opts.Name) {
return fmt.Errorf("Name must be set")
}
if valueSet(opts.OldURL) {
Expand Down Expand Up @@ -386,7 +386,7 @@ func (c *accounts) ShowByID(ctx context.Context, id AccountObjectIdentifier) (*A
return &account, nil
}
}
return nil, errObjectNotExistOrAuthorized
return nil, ErrObjectNotExistOrAuthorized
}

// DropAccountOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-account.
Expand All @@ -399,7 +399,7 @@ type DropAccountOptions struct {
}

func (opts *DropAccountOptions) validate() error {
if !validObjectidentifier(opts.name) {
if !ValidObjectIdentifier(opts.name) {
return fmt.Errorf("Name must be set")
}
if !validateIntGreaterThanOrEqual(opts.gracePeriodInDays, 3) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/sdk/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type AlertCondition struct {
}

func (opts *CreateAlertOptions) validate() error {
if !validObjectidentifier(opts.name) {
if !ValidObjectIdentifier(opts.name) {
return errors.New("invalid object identifier")
}

Expand Down Expand Up @@ -115,7 +115,7 @@ type AlterAlertOptions struct {
}

func (opts *AlterAlertOptions) validate() error {
if !validObjectidentifier(opts.name) {
if !ValidObjectIdentifier(opts.name) {
return errors.New("invalid object identifier")
}

Expand Down Expand Up @@ -175,8 +175,8 @@ type dropAlertOptions struct {
}

func (opts *dropAlertOptions) validate() error {
if !validObjectidentifier(opts.name) {
return errInvalidObjectIdentifier
if !ValidObjectIdentifier(opts.name) {
return ErrInvalidObjectIdentifier
}
return nil
}
Expand Down Expand Up @@ -297,7 +297,7 @@ func (v *alerts) ShowByID(ctx context.Context, id SchemaObjectIdentifier) (*Aler
return &alert, nil
}
}
return nil, errObjectNotExistOrAuthorized
return nil, ErrObjectNotExistOrAuthorized
}

// describeAlertOptions is based on https://docs.snowflake.com/en/sql-reference/sql/desc-alert.
Expand All @@ -308,8 +308,8 @@ type describeAlertOptions struct {
}

func (v *describeAlertOptions) validate() error {
if !validObjectidentifier(v.name) {
return errInvalidObjectIdentifier
if !ValidObjectIdentifier(v.name) {
return ErrInvalidObjectIdentifier
}
return nil
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/sdk/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"fmt"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random"
"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"
)

func TestAlertCreate(t *testing.T) {
id := randomSchemaObjectIdentifier(t)
id := RandomSchemaObjectIdentifier()

t.Run("with complete options", func(t *testing.T) {
newComment := randomString(t)
newComment := random.String()
warehouse := AccountObjectIdentifier{"warehouse"}
existsCondition := "SELECT 1"
condition := AlertCondition{[]string{existsCondition}}
Expand All @@ -39,7 +39,7 @@ func TestAlertCreate(t *testing.T) {
}

func TestAlertAlter(t *testing.T) {
id := randomSchemaObjectIdentifier(t)
id := RandomSchemaObjectIdentifier()

t.Run("fail without alter action specified", func(t *testing.T) {
opts := &AlterAlertOptions{
Expand All @@ -50,7 +50,7 @@ func TestAlertAlter(t *testing.T) {
})

t.Run("fail when 2 alter actions specified", func(t *testing.T) {
newComment := randomString(t)
newComment := random.String()
opts := &AlterAlertOptions{
name: id,
Action: &AlertActionResume,
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestAlertAlter(t *testing.T) {
})

t.Run("with set", func(t *testing.T) {
newComment := randomString(t)
newComment := random.String()
opts := &AlterAlertOptions{
name: id,
Set: &AlertSet{
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestAlertAlter(t *testing.T) {
}

func TestAlertDrop(t *testing.T) {
id := randomSchemaObjectIdentifier(t)
id := RandomSchemaObjectIdentifier()

t.Run("empty options", func(t *testing.T) {
opts := &dropAlertOptions{}
Expand All @@ -172,7 +172,7 @@ func TestAlertDrop(t *testing.T) {
}

func TestAlertShow(t *testing.T) {
id := randomSchemaObjectIdentifier(t)
id := RandomSchemaObjectIdentifier()

t.Run("empty options", func(t *testing.T) {
opts := &ShowAlertOptions{}
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestAlertShow(t *testing.T) {
}

func TestAlertDescribe(t *testing.T) {
id := randomSchemaObjectIdentifier(t)
id := RandomSchemaObjectIdentifier()

t.Run("empty options", func(t *testing.T) {
opts := &describeAlertOptions{}
Expand Down
8 changes: 8 additions & 0 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ type Client struct {
Warehouses Warehouses
}

func (c *Client) GetAccountLocator() string {
return c.accountLocator
}

func (c *Client) GetConfig() *gosnowflake.Config {
return c.config
}

func NewDefaultClient() (*Client, error) {
return NewClient(nil)
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/sdk/collection_helpers.go

This file was deleted.

8 changes: 6 additions & 2 deletions pkg/sdk/database_role_impl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package sdk

import "context"
import (
"context"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections"
)

var _ DatabaseRoles = (*databaseRoles)(nil)

Expand Down Expand Up @@ -42,7 +46,7 @@ func (v *databaseRoles) ShowByID(ctx context.Context, id DatabaseObjectIdentifie
return nil, err
}

return findOne(databaseRoles, func(r DatabaseRole) bool { return r.Name == id.Name() })
return collections.FindOne(databaseRoles, func(r DatabaseRole) bool { return r.Name == id.Name() })
}

func (v *databaseRoles) Grant(ctx context.Context, request *GrantDatabaseRoleRequest) error {
Expand Down
Loading

0 comments on commit 3f528a8

Please sign in to comment.