mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-12 08:00:04 +01:00
Allow database URL to be specified via command line
This commit is contained in:
parent
99a4f266e6
commit
ece5d3cf0e
4 changed files with 36 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue