This can be used in tests to get access to a controller that behaves just like a dev controller but doesn't require the normal Command bits (UI, etc). This can be enhanced over time as needed; for now it's pretty simple but it's good enough to be used for API tests. A simple project create/read API test is added as well, which serves to show the programmatic model (as well as test those functions at the API level).
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package db
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
_ "github.com/golang-migrate/migrate/v4/database/postgres"
|
|
_ "github.com/golang-migrate/migrate/v4/source/file"
|
|
wrapping "github.com/hashicorp/go-kms-wrapping"
|
|
"github.com/hashicorp/go-kms-wrapping/wrappers/aead"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
// setup the tests (initialize the database one-time and intialized testDatabaseURL)
|
|
func TestSetup(t *testing.T, dialect string) (func() error, *gorm.DB, string) {
|
|
cleanup := func() error { return nil }
|
|
var url string
|
|
var err error
|
|
cleanup, url, _, err = InitDbInDocker(dialect)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
db, err := gorm.Open(dialect, url)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return cleanup, db, url
|
|
}
|
|
|
|
// TestWrapper initializes an AEAD wrapping.Wrapper for testing the oplog
|
|
func TestWrapper(t *testing.T) wrapping.Wrapper {
|
|
rootKey := make([]byte, 32)
|
|
n, err := rand.Read(rootKey)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n != 32 {
|
|
t.Fatal(n)
|
|
}
|
|
root := aead.NewWrapper(nil)
|
|
if err := root.SetAESGCMKeyBytes(rootKey); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return root
|
|
}
|