Testing with docker mysqld for golang. Support inside and outside of docker container.
$ go get github.com/soh335/test-mysqld-docker
mysqld, err := mysqltest.NewMysqld(nil)
if err != nil {
log.Fatal(err.Error())
}
db, err := sql.Open("mysql", mysqld.DSN())
if err != nil {
log.Fatal(err.Error())
}
if err := db.Ping(); err != nil {
log.Fatal("ping failed")
}
Require docker command for finding parent conatiner network and ip address of mysql container is created. If you can allow to mount parent docker socket, add -v option like this ( -v /var/run/docker.sock:/var/run/docker.sock
).
- MIT