mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +01:00
Move cmd to project root for easier installs (#29)
This commit is contained in:
parent
e03dec8a04
commit
6ba419a74b
4 changed files with 4 additions and 4 deletions
39
main_test.go
Normal file
39
main_test.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func testContext(t *testing.T, u *url.URL) *cli.Context {
|
||||
var err error
|
||||
|
||||
err = os.Setenv("DATABASE_URL", u.String())
|
||||
require.Nil(t, err)
|
||||
|
||||
app := NewApp()
|
||||
flagset := flag.NewFlagSet(app.Name, flag.ContinueOnError)
|
||||
for _, f := range app.Flags {
|
||||
f.Apply(flagset)
|
||||
}
|
||||
|
||||
return cli.NewContext(app, flagset, nil)
|
||||
}
|
||||
|
||||
func TestGetDatabaseUrl(t *testing.T) {
|
||||
envURL, err := url.Parse("foo://example.org/db")
|
||||
require.Nil(t, err)
|
||||
ctx := testContext(t, envURL)
|
||||
|
||||
u, err := getDatabaseURL(ctx)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, "foo", u.Scheme)
|
||||
require.Equal(t, "example.org", u.Host)
|
||||
require.Equal(t, "/db", u.Path)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue