github.com/qdentity/migrate@v3.3.0+incompatible/source/google_cloud_storage/storage_test.go (about) 1 package googlecloudstorage 2 3 import ( 4 "testing" 5 6 "github.com/fsouza/fake-gcs-server/fakestorage" 7 "github.com/golang-migrate/migrate/source" 8 st "github.com/golang-migrate/migrate/source/testing" 9 ) 10 11 func Test(t *testing.T) { 12 server := fakestorage.NewServer([]fakestorage.Object{ 13 {BucketName: "some-bucket", Name: "staging/migrations/1_foobar.up.sql", Content: []byte("1 up")}, 14 {BucketName: "some-bucket", Name: "staging/migrations/1_foobar.down.sql", Content: []byte("1 down")}, 15 {BucketName: "some-bucket", Name: "prod/migrations/1_foobar.up.sql", Content: []byte("1 up")}, 16 {BucketName: "some-bucket", Name: "prod/migrations/1_foobar.down.sql", Content: []byte("1 down")}, 17 {BucketName: "some-bucket", Name: "prod/migrations/3_foobar.up.sql", Content: []byte("3 up")}, 18 {BucketName: "some-bucket", Name: "prod/migrations/4_foobar.up.sql", Content: []byte("4 up")}, 19 {BucketName: "some-bucket", Name: "prod/migrations/4_foobar.down.sql", Content: []byte("4 down")}, 20 {BucketName: "some-bucket", Name: "prod/migrations/5_foobar.down.sql", Content: []byte("5 down")}, 21 {BucketName: "some-bucket", Name: "prod/migrations/7_foobar.up.sql", Content: []byte("7 up")}, 22 {BucketName: "some-bucket", Name: "prod/migrations/7_foobar.down.sql", Content: []byte("7 down")}, 23 {BucketName: "some-bucket", Name: "prod/migrations/not-a-migration.txt"}, 24 {BucketName: "some-bucket", Name: "prod/migrations/0-random-stuff/whatever.txt"}, 25 }) 26 defer server.Stop() 27 driver := gcs{ 28 bucket: server.Client().Bucket("some-bucket"), 29 prefix: "prod/migrations/", 30 migrations: source.NewMigrations(), 31 } 32 err := driver.loadMigrations() 33 if err != nil { 34 t.Fatal(err) 35 } 36 st.Test(t, &driver) 37 }