-
Notifications
You must be signed in to change notification settings - Fork 32
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
More guardrails around ShouldDeleteFromName
#842
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,43 @@ package ddl | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/artie-labs/transfer/lib/config/constants" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestShouldDeleteFromName(t *testing.T) { | ||
tblsToNotDelete := []string{ | ||
"table", "table_", "table_abcdef9", | ||
fmt.Sprintf("future_table_%d", time.Now().Add(1*time.Hour).Unix()), | ||
} | ||
|
||
for _, tblToNotDelete := range tblsToNotDelete { | ||
assert.False(t, ShouldDeleteFromName(tblToNotDelete), tblToNotDelete) | ||
} | ||
{ | ||
// Tables to not drop | ||
tablesToNotDrop := []string{ | ||
"foo", | ||
"transactions", | ||
fmt.Sprintf("expired_tbl__artie_suffix_%d", time.Now().Add(constants.TemporaryTableTTL).Unix()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup! |
||
fmt.Sprintf("expired_tbl__notartie_%d", time.Now().Add(-1*time.Hour).Unix()), | ||
} | ||
|
||
tblsToDelete := []string{ | ||
fmt.Sprintf("expired_table_%d", time.Now().Add(-1*time.Hour).Unix()), | ||
fmt.Sprintf("expired_tbl__artie_%d", time.Now().Add(-1*time.Hour).Unix()), | ||
fmt.Sprintf("expired_%d", time.Now().Add(-1*time.Hour).Unix()), | ||
for _, tblToNotDelete := range tablesToNotDrop { | ||
assert.False(t, ShouldDeleteFromName(strings.ToLower(tblToNotDelete)), tblToNotDelete) | ||
assert.False(t, ShouldDeleteFromName(strings.ToUpper(tblToNotDelete)), tblToNotDelete) | ||
assert.False(t, ShouldDeleteFromName(tblToNotDelete), tblToNotDelete) | ||
} | ||
} | ||
{ | ||
// Tables that are eligible to be dropped | ||
tablesToDrop := []string{ | ||
"transactions___ARTIE_48GJC_1723663043", | ||
fmt.Sprintf("tableName_%s_suffix_%d", constants.ArtiePrefix, time.Now().Add(-1*constants.TemporaryTableTTL).Unix()), | ||
fmt.Sprintf("artie_%s_suffix_%d", constants.ArtiePrefix, time.Now().Add(-1*constants.TemporaryTableTTL).Unix()), | ||
} | ||
|
||
for _, tblToDelete := range tblsToDelete { | ||
assert.True(t, ShouldDeleteFromName(tblToDelete), tblToDelete) | ||
for _, tblToDelete := range tablesToDrop { | ||
assert.True(t, ShouldDeleteFromName(strings.ToLower(tblToDelete)), tblToDelete) | ||
assert.True(t, ShouldDeleteFromName(strings.ToUpper(tblToDelete)), tblToDelete) | ||
assert.True(t, ShouldDeleteFromName(tblToDelete), tblToDelete) | ||
} | ||
} | ||
} |
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.
Why 6?
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.
That's just how many are in a temp table
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.
At the minimum
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.
I could put it back to 2 if it's confusing?
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.
Oh I see, because right after the table name there are 3 underscores in a row, so 2 of the 6 parts are empty. Maybe it would be more clear to just split the part that comes after the
constants.ArtiePrefix
and check for 2 parts there? Because otherwise if the table name itself has any underscores in it, we could get a false positive here.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.
@danafallon Want to take another look?