@@ -35,7 +35,7 @@ resource "postgresql_function" "basic_function" {
3535 {
3636 Config : config ,
3737 Check : resource .ComposeTestCheckFunc (
38- testAccCheckPostgresqlFunctionExists ("postgresql_function.basic_function" ),
38+ testAccCheckPostgresqlFunctionExists ("postgresql_function.basic_function" , "" ),
3939 resource .TestCheckResourceAttr (
4040 "postgresql_function.basic_function" , "name" , "basic_function" ),
4141 resource .TestCheckResourceAttr (
@@ -46,6 +46,53 @@ resource "postgresql_function" "basic_function" {
4646 })
4747}
4848
49+ func TestAccPostgresqlFunction_SpecificDatabase (t * testing.T ) {
50+ skipIfNotAcc (t )
51+
52+ dbSuffix , teardown := setupTestDatabase (t , true , true )
53+ defer teardown ()
54+
55+ dbName , _ := getTestDBNames (dbSuffix )
56+
57+ config := `
58+ resource "postgresql_function" "basic_function" {
59+ name = "basic_function"
60+ database = "%s"
61+ returns = "integer"
62+ body = <<-EOF
63+ AS $$
64+ BEGIN
65+ RETURN 1;
66+ END;
67+ $$ LANGUAGE plpgsql;
68+ EOF
69+ }
70+ `
71+
72+ resource .Test (t , resource.TestCase {
73+ PreCheck : func () {
74+ testAccPreCheck (t )
75+ testCheckCompatibleVersion (t , featureFunction )
76+ },
77+ Providers : testAccProviders ,
78+ CheckDestroy : testAccCheckPostgresqlFunctionDestroy ,
79+ Steps : []resource.TestStep {
80+ {
81+ Config : fmt .Sprintf (config , dbName ),
82+ Check : resource .ComposeTestCheckFunc (
83+ testAccCheckPostgresqlFunctionExists ("postgresql_function.basic_function" , dbName ),
84+ resource .TestCheckResourceAttr (
85+ "postgresql_function.basic_function" , "name" , "basic_function" ),
86+ resource .TestCheckResourceAttr (
87+ "postgresql_function.basic_function" , "database" , dbName ),
88+ resource .TestCheckResourceAttr (
89+ "postgresql_function.basic_function" , "schema" , "public" ),
90+ ),
91+ },
92+ },
93+ })
94+ }
95+
4996func TestAccPostgresqlFunction_MultipleArgs (t * testing.T ) {
5097 config := `
5198resource "postgresql_schema" "test" {
@@ -86,7 +133,7 @@ resource "postgresql_function" "increment" {
86133 {
87134 Config : config ,
88135 Check : resource .ComposeTestCheckFunc (
89- testAccCheckPostgresqlFunctionExists ("postgresql_function.increment" ),
136+ testAccCheckPostgresqlFunctionExists ("postgresql_function.increment" , "" ),
90137 resource .TestCheckResourceAttr (
91138 "postgresql_function.increment" , "name" , "increment" ),
92139 resource .TestCheckResourceAttr (
@@ -136,7 +183,7 @@ resource "postgresql_function" "func" {
136183 {
137184 Config : configCreate ,
138185 Check : resource .ComposeTestCheckFunc (
139- testAccCheckPostgresqlFunctionExists ("postgresql_function.func" ),
186+ testAccCheckPostgresqlFunctionExists ("postgresql_function.func" , "" ),
140187 resource .TestCheckResourceAttr (
141188 "postgresql_function.func" , "name" , "func" ),
142189 resource .TestCheckResourceAttr (
@@ -146,7 +193,7 @@ resource "postgresql_function" "func" {
146193 {
147194 Config : configUpdate ,
148195 Check : resource .ComposeTestCheckFunc (
149- testAccCheckPostgresqlFunctionExists ("postgresql_function.func" ),
196+ testAccCheckPostgresqlFunctionExists ("postgresql_function.func" , "" ),
150197 resource .TestCheckResourceAttr (
151198 "postgresql_function.func" , "name" , "func" ),
152199 resource .TestCheckResourceAttr (
@@ -157,7 +204,7 @@ resource "postgresql_function" "func" {
157204 })
158205}
159206
160- func testAccCheckPostgresqlFunctionExists (n string ) resource.TestCheckFunc {
207+ func testAccCheckPostgresqlFunctionExists (n string , database string ) resource.TestCheckFunc {
161208 return func (s * terraform.State ) error {
162209 rs , ok := s .RootModule ().Resources [n ]
163210 if ! ok {
@@ -171,7 +218,7 @@ func testAccCheckPostgresqlFunctionExists(n string) resource.TestCheckFunc {
171218 signature := rs .Primary .ID
172219
173220 client := testAccProvider .Meta ().(* Client )
174- txn , err := startTransaction (client , "" )
221+ txn , err := startTransaction (client , database )
175222 if err != nil {
176223 return err
177224 }
0 commit comments