-
Notifications
You must be signed in to change notification settings - Fork 111
/
test_helpers.go
40 lines (36 loc) · 980 Bytes
/
test_helpers.go
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
38
39
40
package postgres
import (
"github.com/chef/automate/components/config-mgmt-service/config"
"github.com/chef/automate/lib/db/migrator"
"github.com/chef/automate/lib/logger"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
func DestructiveReMigrateForTest(cfg *config.Postgres) error {
var err error
pg := New(cfg)
err = pg.Connect()
if err != nil {
return err
}
err = pg.Ping()
if err != nil {
return err
}
err = pg.DestructiveReMigrateForTest()
if err != nil {
return err
}
return pg.Close()
}
func (db *Postgres) DestructiveReMigrateForTest() error {
logger := logger.NewLogrusStandardLogger()
if err := migrator.DestructiveMigrateForTests(db.URI, db.SchemaPath, logger, true); err != nil {
log.WithError(err).WithFields(log.Fields{
"uri": db.URI,
"schema_path": db.SchemaPath,
}).Error("Failed migrating database")
return errors.Wrapf(err, "Unable to create database schema. [path:%s]", db.SchemaPath)
}
return nil
}