@@ -14,6 +14,11 @@ import (
14
14
15
15
var mu sync.Mutex
16
16
17
+ var (
18
+ ErrServerNotStarted = errors .New ("server has not been started" )
19
+ ErrServerAlreadyStarted = errors .New ("server is already started" )
20
+ )
21
+
17
22
// EmbeddedPostgres maintains all configuration and runtime functions for maintaining the lifecycle of one Postgres process.
18
23
type EmbeddedPostgres struct {
19
24
config Config
@@ -63,7 +68,7 @@ func newDatabaseWithConfig(config Config) *EmbeddedPostgres {
63
68
//nolint:funlen
64
69
func (ep * EmbeddedPostgres ) Start () error {
65
70
if ep .started {
66
- return errors . New ( "server is already started" )
71
+ return ErrServerAlreadyStarted
67
72
}
68
73
69
74
if err := ensurePortAvailable (ep .config .port ); err != nil {
@@ -124,7 +129,7 @@ func (ep *EmbeddedPostgres) Start() error {
124
129
if ! reuseData {
125
130
if err := ep .createDatabase (ep .config .port , ep .config .username , ep .config .password , ep .config .database ); err != nil {
126
131
if stopErr := stopPostgres (ep ); stopErr != nil {
127
- return fmt .Errorf ("unable to stop database casused by error %s" , err )
132
+ return fmt .Errorf ("unable to stop database caused by error %s" , err )
128
133
}
129
134
130
135
return err
@@ -133,7 +138,7 @@ func (ep *EmbeddedPostgres) Start() error {
133
138
134
139
if err := healthCheckDatabaseOrTimeout (ep .config ); err != nil {
135
140
if stopErr := stopPostgres (ep ); stopErr != nil {
136
- return fmt .Errorf ("unable to stop database casused by error %s" , err )
141
+ return fmt .Errorf ("unable to stop database caused by error %s" , err )
137
142
}
138
143
139
144
return err
@@ -177,7 +182,7 @@ func (ep *EmbeddedPostgres) cleanDataDirectoryAndInit() error {
177
182
// Stop will try to stop the Postgres process gracefully returning an error when there were any problems.
178
183
func (ep * EmbeddedPostgres ) Stop () error {
179
184
if ! ep .started {
180
- return errors . New ( "server has not been started" )
185
+ return ErrServerNotStarted
181
186
}
182
187
183
188
if err := stopPostgres (ep ); err != nil {
0 commit comments