You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
8 years ago
|
package pgsql
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"path"
|
||
|
"runtime"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/coreos/clair/config"
|
||
|
"github.com/pborman/uuid"
|
||
|
)
|
||
|
|
||
|
func openDatabaseForTest(testName string, loadFixture bool) (*pgSQL, error) {
|
||
|
ds, err := openDatabase(generateTestConfig(testName, loadFixture))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
datastore := ds.(*pgSQL)
|
||
|
return datastore, nil
|
||
|
}
|
||
|
|
||
|
func generateTestConfig(testName string, loadFixture bool) config.RegistrableComponentConfig {
|
||
|
dbName := "test_" + strings.ToLower(testName) + "_" + strings.Replace(uuid.New(), "-", "_", -1)
|
||
|
|
||
|
var fixturePath string
|
||
|
if loadFixture {
|
||
|
_, filename, _, _ := runtime.Caller(0)
|
||
|
fixturePath = path.Join(path.Dir(filename)) + "/testdata/data.sql"
|
||
|
}
|
||
|
|
||
|
source := fmt.Sprintf("postgresql://postgres@127.0.0.1:5432/%s?sslmode=disable", dbName)
|
||
|
if sourceEnv := os.Getenv("CLAIR_TEST_PGSQL"); sourceEnv != "" {
|
||
|
source = fmt.Sprintf(sourceEnv, dbName)
|
||
|
}
|
||
|
|
||
|
return config.RegistrableComponentConfig{
|
||
|
Options: map[string]interface{}{
|
||
|
"source": source,
|
||
|
"cachesize": 0,
|
||
|
"managedatabaselifecycle": true,
|
||
|
"fixturepath": fixturePath,
|
||
|
},
|
||
|
}
|
||
|
}
|