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: Task resource v1 readiness #3113

Merged
merged 14 commits into from
Nov 5, 2024
4 changes: 2 additions & 2 deletions docs/resources/resource_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
page_title: "snowflake_resource_monitor Resource - terraform-provider-snowflake"
subcategory: ""
description: |-

Resource used to manage resource monitor objects. For more information, check resource monitor documentation https://docs.snowflake.com/en/user-guide/resource-monitors.
---

!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0950--v0960) to use it.
Expand All @@ -15,7 +15,7 @@ description: |-

# snowflake_resource_monitor (Resource)


Resource used to manage resource monitor objects. For more information, check [resource monitor documentation](https://docs.snowflake.com/en/user-guide/resource-monitors).

## Example Usage

Expand Down
888 changes: 872 additions & 16 deletions docs/resources/task.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/acceptance/bettertestspoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,5 @@ func (w *WarehouseDatasourceShowOutputAssert) IsEmpty() {
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.
- generate assertions checking that time is not empty - we often do not compare time fields by value, but check if they are set
- Additional asserts for sets and lists that wouldn't rely on the order of items saved to the state (SNOW-1706544)
- support generating provider config and use generated configs in `pkg/provider/provider_acceptance_test.go`
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,37 @@ func (t *TaskAssert) HasTaskRelations(expected sdk.TaskRelations) *TaskAssert {
})
return t
}

func (t *TaskAssert) HasWarehouse(expected *sdk.AccountObjectIdentifier) *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.Warehouse == nil && expected != nil {
return fmt.Errorf("expected warehouse to have value; got: nil")
}
if o.Warehouse != nil && expected == nil {
return fmt.Errorf("expected warehouse to no have value; got: %s", o.Warehouse.Name())
}
if o.Warehouse != nil && expected != nil && o.Warehouse.Name() != expected.Name() {
return fmt.Errorf("expected warehouse: %v; got: %v", expected.Name(), o.Warehouse.Name())
}
return nil
})
return t
}

func (t *TaskAssert) HasErrorIntegration(expected *sdk.AccountObjectIdentifier) *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.ErrorIntegration == nil && expected != nil {
return fmt.Errorf("expected error integration to have value; got: nil")
}
if o.ErrorIntegration != nil && expected == nil {
return fmt.Errorf("expected error integration to have no value; got: %s", o.ErrorIntegration.Name())
}
if o.ErrorIntegration != nil && expected != nil && o.ErrorIntegration.Name() != expected.Name() {
return fmt.Errorf("expected error integration: %v; got: %v", expected.Name(), o.ErrorIntegration.Name())
}
return nil
})
return t
}

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ var allResourceSchemaDefs = []ResourceSchemaDef{
name: "StreamOnView",
schema: resources.StreamOnView().Schema,
},
{
name: "Task",
schema: resources.Task().Schema,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package resourceassert

import (
"fmt"
"strconv"

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

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
)

func (t *TaskResourceAssert) HasAfterIds(ids ...sdk.SchemaObjectIdentifier) *TaskResourceAssert {
t.AddAssertion(assert.ValueSet("after.#", strconv.FormatInt(int64(len(ids)), 10)))
for i, id := range ids {
t.AddAssertion(assert.ValueSet(fmt.Sprintf("after.%d", i), id.FullyQualifiedName()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The order shouldn't matter here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

SHouldn't because the assertion does not have InOrder in name or because Snowflake ordering for alter in non-deterministic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but that should be resolved in newly added TODO for asserts to generate or create a helper for creating asserts for list with non-deterministic order. Right now, this one work (despite being reliant on order) and I would leave it as is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's at least add InOrder suffix to the name of the function then (may be added in the next PR)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this in one of the previous PRs. Snowflake does not guarantee item order, so in general we should compare ID collections, not one by one. For cases where the order matters, we should add a comment about that.

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.

Addressed in: For now, renamed to have InOrder suffix, the limitation of order was added to assert improvements some time ago (it should be in main or in this pr.)

}
return t
}
Loading
Loading