Skip to content

Commit cd07cf7

Browse files
authored
[config.go] Add GetConnectionURL (#108)
* [config.go] Add `GetConnectionURL` * [test_config.go] Add basic test for `GetConnectionURL`
1 parent 9c9e366 commit cd07cf7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config.go

Lines changed: 5 additions & 0 deletions
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"
@@ -118,6 +119,10 @@ func (c Config) BinaryRepositoryURL(binaryRepositoryURL string) Config {
118119
return c
119120
}
120121

122+
func (c Config) GetConnectionURL() string {
123+
return fmt.Sprintf("postgresql://%s:%s@%s:%d/%s", c.username, c.password, "localhost", c.port, c.database)
124+
}
125+
121126
// PostgresVersion represents the semantic version used to fetch and run the Postgres process.
122127
type PostgresVersion string
123128

test_config.go

Lines changed: 12 additions & 0 deletions
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)