Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tasks v1 readiness - SDK part #3086

Merged
merged 13 commits into from
Sep 23, 2024
2 changes: 0 additions & 2 deletions docs/resources/shared_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ resource "snowflake_shared_database" "test" {
from_share = "<primary_account_organization_name>.<primary_account_name>.${snowflake_share.test.name}"
comment = "A shared database"

data_retention_time_in_days = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
Expand Down
2 changes: 0 additions & 2 deletions examples/resources/snowflake_shared_database/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ resource "snowflake_shared_database" "test" {
from_share = "<primary_account_organization_name>.<primary_account_name>.${snowflake_share.test.name}"
comment = "A shared database"

data_retention_time_in_days = 10
max_data_extension_time_in_days = 20
external_volume = "<external_volume_name>"
catalog = "<catalog_name>"
replace_invalid_characters = false
Expand Down
7 changes: 7 additions & 0 deletions pkg/acceptance/bettertestspoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,10 @@ func (w *WarehouseDatasourceShowOutputAssert) IsEmpty() {
- support the rest of attribute types in config model builders (TODO left in `config/model/gen/model.go`)
- parametrize test client helper used - integration versus acceptance tests - this has to be changed in the generator too (TODO left in `assert/objectassert/user_snowflake_ext.go`)
- Omit computed fields in the model (like FullyQualifiedName), because it doesn't make sense to set them
- There's an error when generating models, steps to reproduce:
- Go to view resource code and change `data_metric_function` field to `testing` and make it required
- During the generation, the following error appears: mixed named and unnamed parameters.
It's a golang error indicating that the parameter has both unnamed and named parameters in function (e.g. `func(abc string, int)`).
The error is a result of both things:
1. Lists of objects are partially generated, and only parameter name is generated in some functions (the type has to be added manually).
2. `testing` is a package name that makes Go think that we want to have unnamed parameter there, but we just didn't generate the type for that field in the function argument.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ var allStructs = []SdkObjectDef{
ObjectType: sdk.ObjectTypeAuthenticationPolicy,
ObjectStruct: sdk.AuthenticationPolicy{},
},
{
IdType: "sdk.SchemaObjectIdentifier",
ObjectType: sdk.ObjectTypeTask,
ObjectStruct: sdk.Task{},
},
}

func GetSdkObjectDetails() []genhelpers.SdkObjectDetails {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package objectassert

import (
"errors"
"fmt"
"reflect"
"slices"
"testing"

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

func (t *TaskAssert) HasNotEmptyCreatedOn() *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.CreatedOn == "" {
return fmt.Errorf("expected created on not empty; got: %v", o.CreatedOn)
}
return nil
})
return t
}

func (t *TaskAssert) HasNotEmptyId() *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.Id == "" {
return fmt.Errorf("expected id not empty; got: %v", o.CreatedOn)
}
return nil
})
return t
}

func (t *TaskAssert) HasPredecessors(ids ...sdk.SchemaObjectIdentifier) *TaskAssert {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick: in such assertions (when we require these two lists to match exactly without taking order into account - but this does not matter) it is useful to not only list the missing ids but also list the unexpected ones (and this is how it is usually implemented in the assertion libraries)

Copy link
Collaborator Author

@sfc-gh-jcieslak sfc-gh-jcieslak Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in: Changed the assertions, and added InAnyOrder suffix to this function (on failure all items are printed, so It will be known what was an unexpected item).

t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if len(o.Predecessors) != len(ids) {
return fmt.Errorf("expected %d (%v) predecessors, got %d (%v)", len(ids), ids, len(o.Predecessors), o.Predecessors)
}
var errs []error
for _, id := range ids {
if !slices.ContainsFunc(o.Predecessors, func(predecessorId sdk.SchemaObjectIdentifier) bool {
return predecessorId.FullyQualifiedName() == id.FullyQualifiedName()
}) {
errs = append(errs, fmt.Errorf("expected id: %s, to be in the list of predecessors: %v", id.FullyQualifiedName(), o.Predecessors))
}
}
return errors.Join(errs...)
})
return t
}

func (t *TaskAssert) HasTaskRelations(expected sdk.TaskRelations) *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if len(o.TaskRelations.Predecessors) != len(expected.Predecessors) {
return fmt.Errorf("expected %d (%v) predecessors in task relations, got %d (%v)", len(expected.Predecessors), expected.Predecessors, len(o.TaskRelations.Predecessors), o.TaskRelations.Predecessors)
}
var errs []error
for _, id := range expected.Predecessors {
if !slices.ContainsFunc(o.TaskRelations.Predecessors, func(predecessorId sdk.SchemaObjectIdentifier) bool {
return predecessorId.FullyQualifiedName() == id.FullyQualifiedName()
}) {
errs = append(errs, fmt.Errorf("expected id: %s, to be in the list of predecessors in task relations: %v", id.FullyQualifiedName(), o.TaskRelations.Predecessors))
}
}
if !reflect.DeepEqual(expected.FinalizerTask, o.TaskRelations.FinalizerTask) {
errs = append(errs, fmt.Errorf("expected finalizer task: %v; got: %v", expected.FinalizerTask, o.TaskRelations.FinalizerTask))
}
return errors.Join(errs...)
})
return t
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading