コード例 #1
0
func (w *PostgresDbConnectionTestSuite) Test_ConnectionString(c *gocheck.C) {
	dbConnBlank, _ := baseDbConnection.ComposeDbConnection("", PostgresDbConnection{})

	fullConnectionString := "dbname=" + testDBName + " user="******" password="******" host=" + testDBHost + " port=" + testDBPort + " sslmode=disable"

	c.Assert(dbConnBlank.ConnectionString(), gocheck.Equals, "host=localhost port=5432 sslmode=disable")
	c.Assert(dbConnTest.ConnectionString(), gocheck.Equals, fullConnectionString)
}
コード例 #2
0
func CreateTestDB() *baseDbConnection.DbConnection {
	databaseName := dbConnTest.GenerateRandomDatabaseName()
	newDbUrl := strings.Replace(strings.Replace(testDBUrl, "/"+testDBName, "/"+databaseName, -1), "schema=control", "schema=public", -1)
	dbConnTest.CreateDatabase(databaseName)
	dbConnNew, _ := baseDbConnection.ComposeDbConnection(newDbUrl, PostgresDbConnection{})

	return dbConnNew
}
コード例 #3
0
ファイル: db.go プロジェクト: jrbudnack/cf-sql-broker
// Not a big fan of this pattern, but that's what you get for not supporting
// package level reflection, Golang!!
func New(databaseUrl string) (*DbConnection, error) {
	var err error
	var dbc *baseDbConnection.DbConnection

	if strings.HasPrefix(databaseUrl, "postgres://") {
		dbc, err = baseDbConnection.ComposeDbConnection(databaseUrl, postgresdbconnection.PostgresDbConnection{})
	} else if strings.HasPrefix(databaseUrl, "testdb://") {
		dbc, err = baseDbConnection.ComposeDbConnection(databaseUrl, testDbConnection.TestDbConnection{})
	} else {
		return nil, errors.New("Invalid URL or adapter has not yet been implemented")
	}

	if err != nil {
		return nil, err
	}
	return &DbConnection{*dbc}, nil
}
コード例 #4
0
func (w *PostgresDbConnectionTestSuite) SetUpSuite(c *gocheck.C) {
	testDBUser = os.Getenv("TEST_POSTGRES_DB_CONNECTION_USER")
	testDBPassword = os.Getenv("TEST_POSTGRES_DB_CONNECTION_PASSWORD")
	testDBName = os.Getenv("TEST_POSTGRES_DB_CONNECTION_DBNAME")
	testDBHost = os.Getenv("TEST_POSTGRES_DB_CONNECTION_HOST")
	testDBPort = os.Getenv("TEST_POSTGRES_DB_CONNECTION_PORT")
	testDBUrl =
		"postgres://" + testDBUser + ":" + testDBPassword + "@" + testDBHost + ":" + testDBPort + "/" + testDBName + "?schema=control&connect_timeout=20&sslmode=disable"
	dbConnTest, _ = baseDbConnection.ComposeDbConnection(testDBUrl, PostgresDbConnection{})
}
コード例 #5
0
func (w *PostgresDbConnectionTestSuite) Test_CreateDropDatabase(c *gocheck.C) {
	dbConnNew := CreateTestDB()
	dbConnNew.Connect()

	c.Assert(dbConnNew.IsOpen(), gocheck.Equals, true)

	dbConnNew.Close()

	dbConnTest.DropDatabase(dbConnNew.DBName)

	dbConnNew, _ = baseDbConnection.ComposeDbConnection(dbConnNew.URL.String(), PostgresDbConnection{})

	c.Assert(dbConnNew.IsOpen(), gocheck.Equals, false)
}