Allow database URL to be specified via command line

This commit is contained in:
Adrian Macneil 2015-11-25 11:32:13 -08:00
parent 99a4f266e6
commit ece5d3cf0e
4 changed files with 36 additions and 9 deletions

View file

@ -1,16 +1,29 @@
package main_test
import (
"flag"
"github.com/adrianmacneil/dbmate"
"github.com/codegangsta/cli"
"github.com/stretchr/testify/require"
"os"
"testing"
)
func TestGetDatabaseUrl(t *testing.T) {
func newContext() *cli.Context {
app := main.NewApp()
flagset := flag.NewFlagSet(app.Name, flag.ContinueOnError)
for _, f := range app.Flags {
f.Apply(flagset)
}
return cli.NewContext(app, flagset, nil)
}
func TestGetDatabaseUrl_Default(t *testing.T) {
os.Setenv("DATABASE_URL", "postgres://example.org/db")
u, err := main.GetDatabaseURL()
ctx := newContext()
u, err := main.GetDatabaseURL(ctx)
require.Nil(t, err)
require.Equal(t, "postgres", u.Scheme)