Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08f69ec

Browse files
SamuelMarksStephen Gutekanst
authored and
Stephen Gutekanst
committed
[config.go] Add GetConnectionURL (fergusstrange#108)
* [config.go] Add `GetConnectionURL` * [test_config.go] Add basic test for `GetConnectionURL`
1 parent c7a7704 commit 08f69ec

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package embeddedpostgres
22

33
import (
4+
"fmt"
45
"io"
56
"os"
67
"time"
@@ -126,6 +127,10 @@ func (c Config) BinaryRepositoryURL(binaryRepositoryURL string) Config {
126127
return c
127128
}
128129

130+
func (c Config) GetConnectionURL() string {
131+
return fmt.Sprintf("postgresql://%s:%s@%s:%d/%s", c.username, c.password, "localhost", c.port, c.database)
132+
}
133+
129134
// PostgresVersion represents the semantic version used to fetch and run the Postgres process.
130135
type PostgresVersion string
131136

test_config.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package embeddedpostgres
2+
3+
import "testing"
4+
5+
func TestGetConnectionURL(t *testing.T) {
6+
config := DefaultConfig().Database("mydb").Username("myuser").Password("mypass")
7+
expect := "postgresql://myuser:mypass@localhost:5432/mydb"
8+
9+
if got := config.GetConnectionURL(); got != expect {
10+
t.Errorf("expected \"%s\" got \"%s\"", expect, got)
11+
}
12+
}

0 commit comments

Comments
 (0)