forked from amacneil/dbmate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
37 lines (29 loc) · 748 Bytes
/
main_test.go
File metadata and controls
37 lines (29 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 {
err := os.Setenv("DATABASE_URL", u.String())
require.NoError(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.NoError(t, err)
ctx := testContext(t, envURL)
u, err := getDatabaseURL(ctx)
require.NoError(t, err)
require.Equal(t, "foo", u.Scheme)
require.Equal(t, "example.org", u.Host)
require.Equal(t, "/db", u.Path)
}