Allow not destroying dev databases (#366)

This also shifts some logic around to better prepare for non-dev-mode
workloads, although it does not actually call the KMS creation functions
and initial auth method creation from non-dev commands yet.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-16 10:10:06 -04:00
1 parent c4e2b88022
commit 37e9fed2e3
5 files changed
+124 -50

No files matched your search

+17 -3
View File
@@ -194,9 +194,11 @@ func (tc *TestController) Shutdown() {
if err := tc.b.RunShutdownFuncs(); err != nil {
tc.t.Error(err)
}
if tc.b.DestroyDevDatabase() != nil {
if err := tc.b.DestroyDevDatabase(); err != nil {
tc.t.Error(err)
if !tc.opts.DisableDatabaseDestruction {
if tc.b.DestroyDevDatabase() != nil {
if err := tc.b.DestroyDevDatabase(); err != nil {
tc.t.Error(err)
}
}
}
}
@@ -223,6 +225,10 @@ type TestControllerOpts struct {
// database
DisableDatabaseCreation bool
// DisableDatabaseDestruction can be set true to allow a database to be
// created but examined after-the-fact
DisableDatabaseDestruction bool
// If set, instead of creating a dev database, it will connect to an
// existing database given the url
DatabaseUrl string
@@ -350,6 +356,14 @@ func NewTestController(t *testing.T, opts *TestControllerOpts) *TestController {
if err := tc.b.ConnectToDatabase("postgres"); err != nil {
t.Fatal(err)
}
if err := tc.b.CreateGlobalKmsKeys(); err != nil {
t.Fatal(err)
}
if !opts.DisableAuthMethodCreation {
if err := tc.b.CreateInitialAuthMethod(); err != nil {
t.Fatal(err)
}
}
} else if !opts.DisableDatabaseCreation {
var createOpts []base.Option
if opts.DisableAuthMethodCreation {