-
Notifications
You must be signed in to change notification settings - Fork 5
[Sqldef Pluging] refactor(sqldef) refactor sqldef toolRegistry download binary #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
82d9231
refactor(sqldef) refactor sqldef toolRegistry download binary
kadai0308 d035663
refactor(sqldef) remove binary path cache from stage_plan
kadai0308 2686ee1
refactor(sqldef) fix deployment/stage_plan_test.go
kadai0308 edda8b3
refactor(sqldef) remove useless comment and add TODO to sqldef regist…
kadai0308 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -18,22 +18,86 @@ import ( | |
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/pipe-cd/community-plugins/plugins/sqldef/config" | ||
| "github.com/pipe-cd/piped-plugin-sdk-go/toolregistry/toolregistrytest" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestRegistry_Sqldef(t *testing.T) { | ||
| func TestRegistry_DownloadBinary(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| c := toolregistrytest.NewTestToolRegistry(t) | ||
| tests := []struct { | ||
| name string | ||
| dbType config.DBType | ||
| version string | ||
| expectError bool | ||
| errorMsg string | ||
| }{ | ||
| { | ||
| name: "MySQL_with_specific_version", | ||
| dbType: config.DBTypeMySQL, | ||
| version: "2.0.4", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "MySQL_with_empty_version_should_use_default", | ||
| dbType: config.DBTypeMySQL, | ||
| version: "", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "PostgreSQL_unsupported", | ||
| dbType: config.DBTypePostgres, | ||
| version: "2.0.4", | ||
| expectError: true, | ||
| errorMsg: "unsupported database type: psql, currently only support: mysql", | ||
| }, | ||
| { | ||
| name: "SQLite_unsupported", | ||
| dbType: config.DBTypeSQLite, | ||
| version: "2.0.4", | ||
| expectError: true, | ||
| errorMsg: "unsupported database type: sqlite, currently only support: mysql", | ||
| }, | ||
| { | ||
| name: "MSSQL_unsupported", | ||
| dbType: config.DBTypeMSSQL, | ||
| version: "2.0.4", | ||
| expectError: true, | ||
| errorMsg: "unsupported database type: mssql, currently only support: mysql", | ||
| }, | ||
| } | ||
|
|
||
| r := NewRegistry(c) | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c := toolregistrytest.NewTestToolRegistry(t) | ||
| r := NewRegistry(c) | ||
|
|
||
| path, err := r.Mysqldef(context.Background(), "2.0.4") | ||
| path, err := r.DownloadBinary(context.Background(), tt.dbType, tt.version) | ||
|
|
||
| assert.NoError(t, err) | ||
| require.NotEmpty(t, path) | ||
| if tt.expectError { | ||
| assert.Error(t, err) | ||
| assert.Equal(t, tt.errorMsg, err.Error()) | ||
| assert.Empty(t, path) | ||
| } else { | ||
| assert.NoError(t, err) | ||
| require.NotEmpty(t, path) | ||
|
|
||
| assert.Contains(t, path, "mysqldef-2.0.4", "Expected file title not found in path") | ||
| // For MySQL, verify the path contains the expected binary name | ||
| if tt.dbType == config.DBTypeMySQL { | ||
|
Comment on lines
+87
to
+88
Member
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. add a TODO comment to avoid missing when supporting other types. |
||
| assert.Contains(t, path, "mysqldef", "Expected mysqldef binary name in path") | ||
|
|
||
| // If version was provided, check it's in the path | ||
| if tt.version != "" { | ||
| assert.Contains(t, path, tt.version, "Expected version in path") | ||
| } else { | ||
| // If no version provided, should use default | ||
| assert.Contains(t, path, defaultSqldefVersion, "Expected default version in path") | ||
| } | ||
| } | ||
| // TODO: Add more dbType cases when supported | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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.
I decided to keep it simple, just download the binary every time.