2017-02-09 00:17:04 +00:00
|
|
|
package googlecloudstorage
|
2017-05-14 17:47:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/fsouza/fake-gcs-server/fakestorage"
|
2018-10-10 22:11:48 +00:00
|
|
|
"github.com/golang-migrate/migrate/v4/source"
|
|
|
|
st "github.com/golang-migrate/migrate/v4/source/testing"
|
2017-05-14 17:47:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test(t *testing.T) {
|
|
|
|
server := fakestorage.NewServer([]fakestorage.Object{
|
|
|
|
{BucketName: "some-bucket", Name: "staging/migrations/1_foobar.up.sql", Content: []byte("1 up")},
|
|
|
|
{BucketName: "some-bucket", Name: "staging/migrations/1_foobar.down.sql", Content: []byte("1 down")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/1_foobar.up.sql", Content: []byte("1 up")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/1_foobar.down.sql", Content: []byte("1 down")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/3_foobar.up.sql", Content: []byte("3 up")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/4_foobar.up.sql", Content: []byte("4 up")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/4_foobar.down.sql", Content: []byte("4 down")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/5_foobar.down.sql", Content: []byte("5 down")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/7_foobar.up.sql", Content: []byte("7 up")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/7_foobar.down.sql", Content: []byte("7 down")},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/not-a-migration.txt"},
|
|
|
|
{BucketName: "some-bucket", Name: "prod/migrations/0-random-stuff/whatever.txt"},
|
|
|
|
})
|
|
|
|
defer server.Stop()
|
|
|
|
driver := gcs{
|
|
|
|
bucket: server.Client().Bucket("some-bucket"),
|
|
|
|
prefix: "prod/migrations/",
|
|
|
|
migrations: source.NewMigrations(),
|
|
|
|
}
|
|
|
|
err := driver.loadMigrations()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
st.Test(t, &driver)
|
|
|
|
}
|