Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dogukanayd/go-test-database
go-test-database
https://github.com/dogukanayd/go-test-database
docker docker-sdk go golang test-automation testing unit-testing unittest
Last synced: 9 days ago
JSON representation
go-test-database
- Host: GitHub
- URL: https://github.com/dogukanayd/go-test-database
- Owner: dogukanayd
- License: mit
- Created: 2020-05-11T18:50:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-26T22:19:11.000Z (over 4 years ago)
- Last Synced: 2024-12-16T22:02:03.682Z (about 2 months ago)
- Topics: docker, docker-sdk, go, golang, test-automation, testing, unit-testing, unittest
- Language: Go
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-test-database
#### What this package does?
This package creates up and running mysql container(using docker sdk) for your applications and returns a connection
to the created database, so you can easily query the test database.![alt text](https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcS_5LAwzTqOQRs8pYq_fJHA8n7djUMdcgkeR2Qg69ajuggKXhgm&usqp=CAU)
# Requirements
* :3305 port must not be used
* docker# INSTALL
```bash
go get github.com/dogukanayd/go-test-database
```# USAGE
Let's say you have a package named greetings also in this package you have a function named `Hello`
and this function send some query to the database, well from at this point you need a database separated
from your local database. Here is all you need to do.```go
connection, def := mysql_unit.NewUnit()
```and below you can find full dummy example
```go
package greetingsimport (
mysql_unit "github.com/dogukanayd/go-test-database/mysql-unit"
"log"
"testing"
)func TestHello(t *testing.T) {
connection, def := mysql_unit.NewUnit()q := `CREATE TABLE test_table(id int(11),name varchar(500)) ENGINE = InnoDB DEFAULT CHARSET = utf8;`
_, err := connection.Query(q)
if err != nil {
log.Fatal(err)
}defer def()
t.Log("ping success")
}
```When you call the `NewUnit` function;
```go
connection, tearDown := NewUnit()
```
it's return two parameters;
* connection: *sql.DB // connection that allows you to query the database
* tearDown
here is the defination of the `NewUnit` function;
```go
func NewUnit() (*sql.DB, func()) {}
```