mirror of
https://github.com/status-im/migrate.git
synced 2025-02-22 16:08:04 +00:00
Fix test with optionated drivers
This commit is contained in:
parent
0c7f7b79e0
commit
2957444991
17
.travis.yml
17
.travis.yml
@ -1,4 +1,5 @@
|
||||
language: go
|
||||
sudo :required
|
||||
|
||||
go:
|
||||
- 1.3
|
||||
@ -6,16 +7,12 @@ go:
|
||||
- 1.5
|
||||
- tip
|
||||
|
||||
addons:
|
||||
postgresql: "9.3"
|
||||
|
||||
services:
|
||||
- cassandra
|
||||
- docker
|
||||
|
||||
before_script:
|
||||
- >
|
||||
/usr/local/cassandra/bin/cqlsh -e "CREATE KEYSPACE migratetest WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor' : 1};"
|
||||
- psql -c 'create database migratetest;' -U postgres
|
||||
- mysql -e 'create database migratetest;'
|
||||
before_install:
|
||||
- curl -L https://github.com/docker/compose/releases/download/1.4.2/docker-compose-`uname -s`-`uname -m` > docker-compose
|
||||
- chmod +x docker-compose
|
||||
- sudo mv docker-compose /usr/local/bin
|
||||
|
||||
script: go test -p 1 ./...
|
||||
script: make test
|
||||
|
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM scratch
|
||||
ADD migrate /migrate
|
||||
ENTRYPOINT ["/migrate"]
|
24
Makefile
Normal file
24
Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
IMAGE=mattes/migrate
|
||||
DCR=docker-compose run --rm
|
||||
.PHONY: clean test build release docker-build docker-push run
|
||||
|
||||
all: release
|
||||
|
||||
clean:
|
||||
rm -f migrate
|
||||
|
||||
test:
|
||||
go get -t -v
|
||||
$(DCR) go-test
|
||||
|
||||
build:
|
||||
go get -v -t
|
||||
$(DCR) go-build
|
||||
|
||||
release: test build docker-build docker-push
|
||||
|
||||
docker-build:
|
||||
docker build --rm -t $(IMAGE) .
|
||||
|
||||
docker-push:
|
||||
docker push $(IMAGE)
|
27
docker-compose.yml
Normal file
27
docker-compose.yml
Normal file
@ -0,0 +1,27 @@
|
||||
go: &go
|
||||
image: golang
|
||||
working_dir: /go/src/github.com/mattes/migrate
|
||||
volumes:
|
||||
- $GOPATH:/go
|
||||
- ./migrations:/migrations
|
||||
go-test:
|
||||
<<: *go
|
||||
command: go test -v -cover ./...
|
||||
links:
|
||||
- postgres
|
||||
- mysql
|
||||
- cassandra
|
||||
go-build:
|
||||
<<: *go
|
||||
command: go build -ldflags '-s'
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
postgres:
|
||||
image: postgres
|
||||
mysql:
|
||||
image: mysql
|
||||
environment:
|
||||
MYSQL_DATABASE: migratetest
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
cassandra:
|
||||
image: cassandra
|
@ -2,6 +2,7 @@ package cassandra
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -13,7 +14,10 @@ import (
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
var session *gocql.Session
|
||||
driverUrl := "cassandra://localhost/migratetest"
|
||||
|
||||
host := os.Getenv("CASSANDRA_PORT_9042_TCP_ADDR")
|
||||
port := os.Getenv("CASSANDRA_PORT_9042_TCP_PORT")
|
||||
driverUrl := "cassandra://" + host + ":" + port + "/system"
|
||||
|
||||
// prepare a clean test database
|
||||
u, err := url.Parse(driverUrl)
|
||||
@ -32,12 +36,12 @@ func TestMigrate(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := session.Query(`DROP TABLE IF EXISTS yolo`).Exec(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := session.Query(`DROP TABLE IF EXISTS ` + tableName).Exec(); err != nil {
|
||||
if err := session.Query(`CREATE KEYSPACE IF NOT EXISTS migrate WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};`).Exec(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cluster.Keyspace = "migrate"
|
||||
session, err = cluster.CreateSession()
|
||||
driverUrl = "cassandra://" + host + ":" + port + "/migrate"
|
||||
|
||||
d := &Driver{}
|
||||
if err := d.Initialize(driverUrl); err != nil {
|
||||
|
@ -52,9 +52,12 @@ func New(url string) (Driver, error) {
|
||||
err := errors.New(fmt.Sprintf("Driver '%s' does not implement the Driver interface"))
|
||||
return nil, err
|
||||
}
|
||||
verifyFilenameExtension(u.Scheme, d)
|
||||
if err := d.Initialize(url); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d, nil
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("Driver '%s' not found.", u.Scheme))
|
||||
}
|
||||
return nil, fmt.Errorf("Driver '%s' not found.", u.Scheme)
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package driver
|
||||
|
||||
import "testing"
|
||||
import _ "github.com/mattes/migrate/driver/bash"
|
||||
import _ "github.com/mattes/migrate/driver/sqlite3"
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
if _, err := New("unknown://url"); err == nil {
|
||||
|
@ -2,17 +2,21 @@ package mysql
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattes/migrate/file"
|
||||
"github.com/mattes/migrate/migrate/direction"
|
||||
pipep "github.com/mattes/migrate/pipe"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMigrate runs some additional tests on Migrate().
|
||||
// Basic testing is already done in migrate/migrate_test.go
|
||||
func TestMigrate(t *testing.T) {
|
||||
driverUrl := "mysql://root@tcp(127.0.0.1:3306)/migratetest"
|
||||
host := os.Getenv("MYSQL_PORT_3306_TCP_ADDR")
|
||||
port := os.Getenv("MYSQL_PORT_3306_TCP_PORT")
|
||||
driverUrl := "mysql://root@tcp(" + host + ":" + port + ")/migratetest"
|
||||
|
||||
// prepare clean database
|
||||
connection, err := sql.Open("mysql", strings.SplitN(driverUrl, "mysql://", 2)[1])
|
||||
|
@ -5,11 +5,12 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/mattes/migrate/driver/registry"
|
||||
"github.com/mattes/migrate/file"
|
||||
"github.com/mattes/migrate/migrate/direction"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Driver struct {
|
||||
|
@ -2,16 +2,20 @@ package postgres
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/mattes/migrate/file"
|
||||
"github.com/mattes/migrate/migrate/direction"
|
||||
pipep "github.com/mattes/migrate/pipe"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMigrate runs some additional tests on Migrate().
|
||||
// Basic testing is already done in migrate/migrate_test.go
|
||||
func TestMigrate(t *testing.T) {
|
||||
driverUrl := "postgres://localhost/migratetest?sslmode=disable"
|
||||
host := os.Getenv("POSTGRES_PORT_5432_TCP_ADDR")
|
||||
port := os.Getenv("POSTGRES_PORT_5432_TCP_PORT")
|
||||
driverUrl := "postgres://postgres@" + host + ":" + port + "/template1?sslmode=disable"
|
||||
|
||||
// prepare clean database
|
||||
connection, err := sql.Open("postgres", driverUrl)
|
||||
|
@ -2,10 +2,11 @@ package sqlite3
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"github.com/mattes/migrate/file"
|
||||
"github.com/mattes/migrate/migrate/direction"
|
||||
pipep "github.com/mattes/migrate/pipe"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMigrate runs some additional tests on Migrate()
|
||||
|
@ -2,6 +2,7 @@ package migrate
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
// Ensure imports for each driver we wish to test
|
||||
_ "github.com/mattes/migrate/driver/postgres"
|
||||
@ -9,7 +10,7 @@ import (
|
||||
|
||||
// Add Driver URLs here to test basic Up, Down, .. functions.
|
||||
var driverUrls = []string{
|
||||
"postgres://localhost/migratetest?sslmode=disable",
|
||||
"postgres://postgres@" + os.Getenv("POSTGRES_PORT_5432_TCP_ADDR") + ":" + os.Getenv("POSTGRES_PORT_5432_TCP_PORT") + "/template1?sslmode=disable",
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
@ -56,7 +57,7 @@ func TestCreate(t *testing.T) {
|
||||
func TestReset(t *testing.T) {
|
||||
for _, driverUrl := range driverUrls {
|
||||
t.Logf("Test driver: %s", driverUrl)
|
||||
tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
|
||||
tmpdir, err := ioutil.TempDir("/", "migrate-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user