2015-10-11 06:01:49 +02:00
|
|
|
package influxdb
|
|
|
|
|
|
|
|
import (
|
2016-08-05 08:27:03 +02:00
|
|
|
"fmt"
|
2015-10-11 06:01:49 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2016-08-05 08:27:03 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
"github.com/influxdata/influxdb/client"
|
2015-10-11 06:01:49 +02:00
|
|
|
)
|
|
|
|
|
2016-08-05 08:27:03 +02:00
|
|
|
func TestAccInfluxDBDatabase(t *testing.T) {
|
2015-10-11 06:01:49 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccDatabaseConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2016-08-05 08:27:03 +02:00
|
|
|
testAccCheckDatabaseExists("influxdb_database.test"),
|
2015-10-11 06:01:49 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"influxdb_database.test", "name", "terraform-test",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-05 08:27:03 +02:00
|
|
|
func testAccCheckDatabaseExists(n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No database id set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*client.Client)
|
|
|
|
|
|
|
|
query := client.Query{
|
|
|
|
Command: "SHOW DATABASES",
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := conn.Query(query)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Err != nil {
|
|
|
|
return resp.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, result := range resp.Results[0].Series[0].Values {
|
|
|
|
if result[0] == rs.Primary.Attributes["name"] {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Database %q does not exist", rs.Primary.Attributes["name"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 06:01:49 +02:00
|
|
|
var testAccDatabaseConfig = `
|
|
|
|
|
|
|
|
resource "influxdb_database" "test" {
|
|
|
|
name = "terraform-test"
|
|
|
|
}
|
|
|
|
|
|
|
|
`
|