Skip to content

Commit

Permalink
internal stage integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Nov 2, 2023
1 parent 8131b06 commit 2f2426e
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 43 deletions.
15 changes: 7 additions & 8 deletions pkg/sdk/stages_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func alterStageOperation(structName string, apply func(qs *g.QueryStruct) *g.Que

var stageFileFormatDef = g.NewQueryStruct("StageFileFormat").
OptionalTextAssignment("FORMAT_NAME", g.ParameterOptions().SingleQuotes()).
OptionalAssignment("TYPE", g.KindOfTPointer[FileFormatType](), g.ParameterOptions()).
List("TYPE", g.KindOfT[FileFormatType](), g.ListOptions())
OptionalAssignment("TYPE", g.KindOfTPointer[FileFormatType](), g.ParameterOptions())

var stageCopyOptionsDef = g.NewQueryStruct("StageCopyOptions").
OptionalQueryStructField(
Expand Down Expand Up @@ -344,14 +343,14 @@ var StagesDef = g.NewInterface(
Field("parent_property", "string").
Field("property", "string").
Field("property_type", "string").
Field("property_value", "sql.NullString").
Field("property_default", "sql.NullString"),
Field("property_value", "string").
Field("property_default", "string"),
g.PlainStruct("StageProperty").
Field("Parent", "string").
Field("Name", "string").
Field("Type", "string").
Field("Value", "*string").
Field("Default", "*string"),
Field("Value", "string").
Field("Default", "string"),
g.NewQueryStruct("DescStage").
Describe().
SQL("STAGE").
Expand All @@ -370,7 +369,7 @@ var StagesDef = g.NewInterface(
Field("has_encryption_key", "string").
Field("owner", "string").
Field("comment", "string").
Field("region", "string").
Field("region", "sql.NullString").
Field("type", "string").
Field("cloud", "sql.NullString").
Field("storage_integration", "sql.NullString").
Expand All @@ -387,7 +386,7 @@ var StagesDef = g.NewInterface(
Field("HasEncryptionKey", "bool").
Field("Owner", "string").
Field("Comment", "string").
Field("Region", "string").
Field("Region", "*string").
Field("Type", "string").
Field("Cloud", "*string").
Field("StorageIntegration", "*string").
Expand Down
26 changes: 17 additions & 9 deletions pkg/sdk/stages_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,19 @@ type DescribeStageOptions struct {
}

type stageDescRow struct {
ParentProperty string `db:"parent_property"`
Property string `db:"property"`
PropertyType string `db:"property_type"`
PropertyValue sql.NullString `db:"property_value"`
PropertyDefault sql.NullString `db:"property_default"`
ParentProperty string `db:"parent_property"`
Property string `db:"property"`
PropertyType string `db:"property_type"`
PropertyValue string `db:"property_value"`
PropertyDefault string `db:"property_default"`
}

type StageProperty struct {
Parent string
Name string
Type string
Value *string
Default *string
Value string
Default string
}

// ShowStageOptions is based on https://docs.snowflake.com/en/sql-reference/sql/show-stages.
Expand All @@ -339,7 +339,7 @@ type stageShowRow struct {
HasEncryptionKey string `db:"has_encryption_key"`
Owner string `db:"owner"`
Comment string `db:"comment"`
Region string `db:"region"`
Region sql.NullString `db:"region"`
Type string `db:"type"`
Cloud sql.NullString `db:"cloud"`
StorageIntegration sql.NullString `db:"storage_integration"`
Expand All @@ -358,11 +358,19 @@ type Stage struct {
HasEncryptionKey bool
Owner string
Comment string
Region string
Region *string
Type string
Cloud *string
StorageIntegration *string
Endpoint *string
OwnerRoleType *string
DirectoryEnabled bool
}

func (s *Stage) ID() SchemaObjectIdentifier {
return NewSchemaObjectIdentifier(s.DatabaseName, s.SchemaName, s.Name)
}

func (s *Stage) ObjectType() ObjectType {
return ObjectTypeStage
}
44 changes: 39 additions & 5 deletions pkg/sdk/stages_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sdk

import (
"context"

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

Expand Down Expand Up @@ -641,8 +640,14 @@ func (r *DescribeStageRequest) toOpts() *DescribeStageOptions {
}

func (r stageDescRow) convert() *StageProperty {
// TODO: Mapping
return &StageProperty{}
stageProp := &StageProperty{
Parent: r.ParentProperty,
Name: r.Property,
Type: r.PropertyType,
Value: r.PropertyValue,
Default: r.PropertyDefault,
}
return stageProp
}

func (r *ShowStageRequest) toOpts() *ShowStageOptions {
Expand All @@ -654,6 +659,35 @@ func (r *ShowStageRequest) toOpts() *ShowStageOptions {
}

func (r stageShowRow) convert() *Stage {
// TODO: Mapping
return &Stage{}
stage := &Stage{
CreatedOn: r.CreatedOn,
Name: r.Name,
DatabaseName: r.DatabaseName,
SchemaName: r.SchemaName,
Url: r.Url,
// TODO: Check in worksheet
HasCredentials: r.HasCredentials == "Y",
HasEncryptionKey: r.HasEncryptionKey == "Y",
Owner: r.Owner,
Comment: r.Comment,
Type: r.Type,
DirectoryEnabled: r.DirectoryEnabled == "Y",
}
if r.Region.Valid {
stage.Region = &r.Region.String
}
// TODO: Check in worksheet or in test
if r.Cloud.Valid { // && r.Cloud.String != "NULL" {
stage.Cloud = &r.Cloud.String
}
if r.StorageIntegration.Valid {
stage.StorageIntegration = &r.StorageIntegration.String
}
if r.Endpoint.Valid {
stage.Endpoint = &r.Endpoint.String
}
if r.OwnerRoleType.Valid {
stage.OwnerRoleType = &r.OwnerRoleType.String
}
return stage
}
18 changes: 6 additions & 12 deletions pkg/sdk/testint/file_format_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) {
CSVEmptyFieldAsNull: sdk.Bool(true),
CSVSkipByteOrderMark: sdk.Bool(true),
CSVEncoding: &sdk.CSVEncodingGB18030,

Comment: sdk.String("test comment"),
},
Comment: sdk.String("test comment"),
})
require.NoError(t, err)
t.Cleanup(func() {
Expand Down Expand Up @@ -122,9 +121,8 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) {
JSONStripNullValues: sdk.Bool(true),
JSONIgnoreUTF8Errors: sdk.Bool(true),
JSONSkipByteOrderMark: sdk.Bool(true),

Comment: sdk.String("test comment"),
},
Comment: sdk.String("test comment"),
})
require.NoError(t, err)
t.Cleanup(func() {
Expand Down Expand Up @@ -184,9 +182,8 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) {
AvroTrimSpace: sdk.Bool(true),
AvroReplaceInvalidCharacters: sdk.Bool(true),
AvroNullIf: &[]sdk.NullString{{S: "a"}, {S: "b"}},

Comment: sdk.String("test comment"),
},
Comment: sdk.String("test comment"),
})
require.NoError(t, err)
t.Cleanup(func() {
Expand Down Expand Up @@ -225,9 +222,8 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) {
ORCTrimSpace: sdk.Bool(true),
ORCReplaceInvalidCharacters: sdk.Bool(true),
ORCNullIf: &[]sdk.NullString{{S: "a"}, {S: "b"}},

Comment: sdk.String("test comment"),
},
Comment: sdk.String("test comment"),
})
require.NoError(t, err)
t.Cleanup(func() {
Expand Down Expand Up @@ -266,9 +262,8 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) {
ParquetTrimSpace: sdk.Bool(true),
ParquetReplaceInvalidCharacters: sdk.Bool(true),
ParquetNullIf: &[]sdk.NullString{{S: "a"}, {S: "b"}},

Comment: sdk.String("test comment"),
},
Comment: sdk.String("test comment"),
})
require.NoError(t, err)
t.Cleanup(func() {
Expand Down Expand Up @@ -313,9 +308,8 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) {
XMLDisableSnowflakeData: sdk.Bool(true),
XMLDisableAutoConvert: sdk.Bool(true),
XMLSkipByteOrderMark: sdk.Bool(true),

Comment: sdk.String("test comment"),
},
Comment: sdk.String("test comment"),
})
require.NoError(t, err)
t.Cleanup(func() {
Expand Down
Loading

0 comments on commit 2f2426e

Please sign in to comment.