-
-
Notifications
You must be signed in to change notification settings - Fork 478
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
Mysql canned container #59
Conversation
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.
some comments, but I like the general approach
canned/mysql.go
Outdated
ctx context.Context | ||
} | ||
|
||
func (c *mysqlContainer) GetDriver(username, password, database string) (*sql.DB, error) { |
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.
Consider taking the parameters from the request and fallbacking to the defaults of the image
canned/mysql.go
Outdated
return nil, err | ||
} | ||
|
||
req.Image = "mysql:8.0" |
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.
Consider making the version configurable from the request and having a default in a package constant.
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.
Maybe also make the image configurable so somebody can choose a custom image that is compatible with the options of the default image
canned/mysql.go
Outdated
req.Image = "mysql:8.0" | ||
req.ExposedPorts = []string{"3306/tcp"} | ||
req.Env = map[string]string{} | ||
req.Started = true |
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.
All these options basicly overwrite options that may be set by a user. Try checking if this is empty in the ContainerRequest
canned/mysql.go
Outdated
req.Env["MYSQL_DATABASE"] = req.Database | ||
} | ||
|
||
req.WaitingFor = wait.ForLog("port: 3306 MySQL Community Server - GPL") |
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.
The java implementation actually tries connecting via a mysql client to verify that the database is ready.
canned/mysql.go
Outdated
Container: c, | ||
} | ||
mysqlC.req = req | ||
mysqlC.ctx = ctx |
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.
This is not a common pattern since a context is usually valid for a single function call. Consider e.g. context.WithTimeout()
canned/mysql.go
Outdated
if err := c.Start(ctx); err != nil { | ||
return mysqlC, errors.Wrap(err, "failed to start container") | ||
} | ||
} |
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.
is this functionality not implemented in the testcontainer-go core?
Sorry, I've been away on vacation with limited internet access. Love the direction, and I agree with most of @mraerino's points :) |
Reference #19 I bootstrapped a mysql canned container. ``` ctx := context.Background() c, err := MySQLContainer(ctx, MySQLContainerRequest{ RootPassword: "root", Database: "hello", }) if err != nil { t.Fatal(err.Error()) } defer c.Container.Terminate(ctx) sqlC, err := c.GetDriver("root", "root", "hello") if err != nil { t.Fatal(err.Error()) } _, err = sqlC.ExecContext(ctx, "CREATE TABLE example ( id integer, data varchar(32) )") if err != nil { t.Fatal(err.Error()) } ``` Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
c8eeaa4
to
cd69c00
Compare
) | ||
|
||
type MySQLContainerRequest struct { | ||
testcontainers.GenericContainerRequest |
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 think we should not accept a request here, we should build it based on what we know from the image the other params we get from the user. What do you think? @mraerino @alde
As a canned container, it should be easy to use and the fact that it can pass the entire request makes it more confused, hard to use to write for what I can see since today.
Reference #19
I bootstrapped a mysql canned container.
Signed-off-by: Gianluca Arbezzano gianarb92@gmail.com