-
Notifications
You must be signed in to change notification settings - Fork 2
Add MySQLProvider and register at startup #33
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,8 @@ import ( | |||||||||||||||
| "github.com/ProxySQL/dbdeployer/defaults" | ||||||||||||||||
| "github.com/ProxySQL/dbdeployer/downloads" | ||||||||||||||||
| "github.com/ProxySQL/dbdeployer/globals" | ||||||||||||||||
| "github.com/ProxySQL/dbdeployer/providers" | ||||||||||||||||
| mysqlprovider "github.com/ProxySQL/dbdeployer/providers/mysql" | ||||||||||||||||
| "github.com/ProxySQL/dbdeployer/sandbox" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -143,6 +145,9 @@ func customizeFlags(cmd *cobra.Command, cmdName string) { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func init() { | ||||||||||||||||
| if err := mysqlprovider.Register(providers.DefaultRegistry); err != nil { | ||||||||||||||||
| panic(fmt.Sprintf("failed to register MySQL provider: %v", err)) | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+148
to
+150
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. Using
Suggested change
|
||||||||||||||||
| cobra.OnInitialize(checkDefaultsFile) | ||||||||||||||||
| rootCmd.CompletionOptions.DisableDefaultCmd = true | ||||||||||||||||
| rootCmd.PersistentFlags().StringVar(&defaults.CustomConfigurationFile, globals.ConfigLabel, defaults.ConfigurationFile, "configuration file") | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package mysql | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/ProxySQL/dbdeployer/providers" | ||
| ) | ||
|
|
||
| const ProviderName = "mysql" | ||
|
|
||
| type MySQLProvider struct{} | ||
|
|
||
| func NewMySQLProvider() *MySQLProvider { | ||
| return &MySQLProvider{} | ||
| } | ||
|
|
||
| func (p *MySQLProvider) Name() string { return ProviderName } | ||
|
|
||
| func (p *MySQLProvider) ValidateVersion(version string) error { | ||
| parts := strings.Split(version, ".") | ||
| if len(parts) < 2 { | ||
| return fmt.Errorf("invalid MySQL version format: %q (expected X.Y or X.Y.Z)", version) | ||
| } | ||
| return nil | ||
|
Comment on lines
+20
to
+25
|
||
| } | ||
|
Comment on lines
+20
to
+26
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. The current version validation only checks for the presence of at least one dot ( func (p *MySQLProvider) ValidateVersion(version string) error {
parts := strings.Split(version, ".")
if len(parts) < 2 {
return fmt.Errorf("invalid MySQL version format: %q (expected X.Y or X.Y.Z)", version)
}
for _, part := range parts {
if _, err := strconv.Atoi(part); err != nil {
return fmt.Errorf("invalid numeric part in version string %q: %s", version, part)
}
}
return nil
} |
||
|
|
||
| func (p *MySQLProvider) DefaultPorts() providers.PortRange { | ||
| return providers.PortRange{ | ||
| BasePort: 3306, | ||
| PortsPerInstance: 3, // main + mysqlx + admin | ||
| } | ||
| } | ||
|
|
||
| func Register(reg *providers.Registry) error { | ||
| return reg.Register(NewMySQLProvider()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package mysql | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ProxySQL/dbdeployer/providers" | ||
| ) | ||
|
|
||
| func TestMySQLProviderName(t *testing.T) { | ||
| p := NewMySQLProvider() | ||
| if p.Name() != "mysql" { | ||
| t.Errorf("expected 'mysql', got %q", p.Name()) | ||
| } | ||
| } | ||
|
|
||
| func TestMySQLProviderValidateVersion(t *testing.T) { | ||
| p := NewMySQLProvider() | ||
| tests := []struct { | ||
| version string | ||
| wantErr bool | ||
| }{ | ||
| {"8.4.4", false}, | ||
| {"9.1.0", false}, | ||
| {"5.7", false}, | ||
| {"invalid", true}, | ||
|
Comment on lines
+22
to
+25
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. The test suite for {"8.4.4", false},
{"9.1.0", false},
{"5.7", false},
{"invalid", true},
{"5.a", true},
{"a.5", true},
{"5.7.", true}, |
||
| } | ||
| for _, tt := range tests { | ||
| err := p.ValidateVersion(tt.version) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("ValidateVersion(%q) error = %v, wantErr %v", tt.version, err, tt.wantErr) | ||
| } | ||
| } | ||
|
Comment on lines
+16
to
+32
|
||
| } | ||
|
|
||
| func TestMySQLProviderRegister(t *testing.T) { | ||
| reg := providers.NewRegistry() | ||
| if err := Register(reg); err != nil { | ||
| t.Fatalf("Register failed: %v", err) | ||
| } | ||
| p, err := reg.Get("mysql") | ||
| if err != nil { | ||
| t.Fatalf("Get failed: %v", err) | ||
| } | ||
| if p.Name() != "mysql" { | ||
| t.Errorf("expected 'mysql', got %q", p.Name()) | ||
| } | ||
| } | ||
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.
Using
panicininit()will produce a stack trace if registration ever fails (e.g., duplicate registration), which is a user-facing behavior change compared to the rest of the CLI error handling (which typically prints a message and exits). Consider switching to a controlled exit path (e.g.,common.Exitf(1, ...)or deferring provider registration toExecute()where errors can be returned/printed cleanly).