@@ -3,6 +3,7 @@ package embeddedpostgres
33import (
44 "errors"
55 "fmt"
6+ "io"
67 "log"
78 "net"
89 "os"
@@ -75,7 +76,7 @@ func (ep *EmbeddedPostgres) Start() error {
7576 return fmt .Errorf ("unable to extract postgres archive %s to %s" , cacheLocation , binaryExtractLocation )
7677 }
7778
78- if err := ep .initDatabase (binaryExtractLocation , ep .config .username , ep .config .password , ep .config .locale ); err != nil {
79+ if err := ep .initDatabase (binaryExtractLocation , ep .config .username , ep .config .password , ep .config .locale , ep . config . logger ); err != nil {
7980 return err
8081 }
8182
@@ -86,15 +87,15 @@ func (ep *EmbeddedPostgres) Start() error {
8687 ep .started = true
8788
8889 if err := ep .createDatabase (ep .config .port , ep .config .username , ep .config .password , ep .config .database ); err != nil {
89- if stopErr := stopPostgres (binaryExtractLocation ); stopErr != nil {
90+ if stopErr := stopPostgres (binaryExtractLocation , ep . config . logger ); stopErr != nil {
9091 return fmt .Errorf ("unable to stop database casused by error %s" , err )
9192 }
9293
9394 return err
9495 }
9596
9697 if err := healthCheckDatabaseOrTimeout (ep .config ); err != nil {
97- if stopErr := stopPostgres (binaryExtractLocation ); stopErr != nil {
98+ if stopErr := stopPostgres (binaryExtractLocation , ep . config . logger ); stopErr != nil {
9899 return fmt .Errorf ("unable to stop database casused by error %s" , err )
99100 }
100101
@@ -112,7 +113,7 @@ func (ep *EmbeddedPostgres) Stop() error {
112113 }
113114
114115 binaryExtractLocation := userLocationOrDefault (ep .config .runtimePath , cacheLocation )
115- if err := stopPostgres (binaryExtractLocation ); err != nil {
116+ if err := stopPostgres (binaryExtractLocation , ep . config . logger ); err != nil {
116117 return err
117118 }
118119
@@ -127,8 +128,8 @@ func startPostgres(binaryExtractLocation string, config Config) error {
127128 "-D" , filepath .Join (binaryExtractLocation , "data" ),
128129 "-o" , fmt .Sprintf (`"-p %d"` , config .port ))
129130 log .Println (postgresProcess .String ())
130- postgresProcess .Stderr = os . Stderr
131- postgresProcess .Stdout = os . Stdout
131+ postgresProcess .Stderr = config . logger
132+ postgresProcess .Stdout = config . logger
132133
133134 if err := postgresProcess .Run (); err != nil {
134135 return fmt .Errorf ("could not start postgres using %s" , postgresProcess .String ())
@@ -137,12 +138,12 @@ func startPostgres(binaryExtractLocation string, config Config) error {
137138 return nil
138139}
139140
140- func stopPostgres (binaryExtractLocation string ) error {
141+ func stopPostgres (binaryExtractLocation string , logger io. Writer ) error {
141142 postgresBinary := filepath .Join (binaryExtractLocation , "bin/pg_ctl" )
142143 postgresProcess := exec .Command (postgresBinary , "stop" , "-w" ,
143144 "-D" , filepath .Join (binaryExtractLocation , "data" ))
144- postgresProcess .Stderr = os . Stderr
145- postgresProcess .Stdout = os . Stdout
145+ postgresProcess .Stderr = logger
146+ postgresProcess .Stdout = logger
146147
147148 return postgresProcess .Run ()
148149}
0 commit comments