-
Notifications
You must be signed in to change notification settings - Fork 420
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
39c6bcf
wip
sfc-gh-jcieslak fff9b1e
wip
sfc-gh-jcieslak 110d00a
Passing tests
sfc-gh-jcieslak 59d2fa4
Added create or alter test
sfc-gh-jcieslak 1224a7d
wip
sfc-gh-jcieslak 56b338b
wip
sfc-gh-jcieslak e076055
wip
sfc-gh-jcieslak 5e808d1
wip
sfc-gh-jcieslak 65ece76
changes after review
sfc-gh-jcieslak 554fc90
changes after review
sfc-gh-jcieslak 87638ea
lint fix
sfc-gh-jcieslak a783bec
Changes after review
sfc-gh-jcieslak fc5586e
Changes after review
sfc-gh-jcieslak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
pkg/acceptance/bettertestspoc/assert/objectassert/task_snowflake_ext.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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 | ||
} |
251 changes: 251 additions & 0 deletions
251
pkg/acceptance/bettertestspoc/assert/objectassert/task_snowflake_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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).