Skip to content
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

Implement database containers #19

Closed
mraerino opened this issue Nov 22, 2018 · 8 comments
Closed

Implement database containers #19

mraerino opened this issue Nov 22, 2018 · 8 comments

Comments

@mraerino
Copy link
Contributor

The java implementation of testcontainers provides useful preconfigured setups for certain databases.
They usually predefine an image and setup the special waiting strategy for that database.

This should be straight-forward for Go as well since there are many database clients around to do this.

I think I'll get started with a postgres setup.

@gianarb
Copy link
Collaborator

gianarb commented Nov 23, 2018

Yep, this looks like a great idea. Can you write down some code here to help me understand how you imagine interacting with the postgres utils? probably just a fake test is enough

@gianarb
Copy link
Collaborator

gianarb commented Apr 10, 2019

Should we start packaging this kind of solutions in a subpackage? Maybe a directory called canned?

	ctx := context.Background()
	mySql, err := canned.MySqlContainer(ctx, testcontainers.GenericContainerRequest{
		Started:          true,
	})
        mySql.GetClient() // returns a SQL client ready to be used

Having a testcontainers.GenericContainerRequest as a second parameter should give us all the flexibility we need because if something weird is required you can set your own request.

The MySql Container will attach the Log waiter and it will serve the right client

gianarb pushed a commit that referenced this issue Apr 20, 2019
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>
gianarb pushed a commit that referenced this issue Nov 21, 2019
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>
@fbiville
Copy link
Contributor

I'd be happy to write a Neo4j integration.

@orlangure
Copy link

While this is being implemented, you might try using Gnomock which sets up databases and other services, and includes initial state setup features.

@gianarb
Copy link
Collaborator

gianarb commented Jan 18, 2021

I am gonna this issue for now! As you can read in our documentation Golang is not really flexible when it comes to managing multiple modules in the same project and dependency management is still a pain.

https://golang.testcontainers.org/modules/

We decided to stay focused on the core library for now. If you decide to develop your module open a PR and link it in our documentation. We are happy to share it with the community but not to maintain it directly at this stage ❤️

@gianarb gianarb closed this as completed Jan 18, 2021
@fbiville
Copy link
Contributor

Hello @gianarb, I'm wondering if you'd reconsider integrating database modules today?
What are the blockers in terms of multi-module management?
Couldn't each DB module have their go.mod and depend on the local main testcontainers module with a replace clause?

@mdelapenya
Copy link
Collaborator

We started this PR, which could be the seed for modules: #618

It creates examples to be consumed by the website, but turning them into modules would be a matter of adjusting the templates.

@mdelapenya
Copy link
Collaborator

Given #618 has been merged, we created #636, where you can find how to contribute new modules :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants