Skip to content

Commit

Permalink
Added new test
Browse files Browse the repository at this point in the history
Added data source instances test
Fix error in the documentation for instances data source

Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
  • Loading branch information
alejandrojnm committed Jul 5, 2020
1 parent 834a4e3 commit 4f3a1a1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
63 changes: 63 additions & 0 deletions civo/datasource_instances_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package civo

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceCivoInstances_basic(t *testing.T) {
var instanceHostname = acctest.RandomWithPrefix("tf-test")
var instanceHostname2 = acctest.RandomWithPrefix("tf-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCivoInstancesConfig(instanceHostname, instanceHostname2),
},
{
Config: testAccDataSourceCivoInstancesDataConfig(instanceHostname, instanceHostname2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.civo_instances.result", "instances.#", "1"),
resource.TestCheckResourceAttr("data.civo_instances.result", "instances.0.hostname", instanceHostname),
resource.TestCheckResourceAttrPair("data.civo_instances.result", "instances.0.id", "civo_instance.foo", "id"),
),
},
},
})
}

func testAccDataSourceCivoInstancesConfig(name string, name2 string) string {
return fmt.Sprintf(`
resource "civo_instance" "foo" {
hostname = "%s"
}
resource "civo_instance" "bar" {
hostname = "%s"
}
`, name, name2)
}

func testAccDataSourceCivoInstancesDataConfig(name string, name2 string) string {
return fmt.Sprintf(`
resource "civo_instance" "foo" {
hostname = "%s"
}
resource "civo_instance" "bar" {
hostname = "%s"
}
data "civo_instances" "result" {
filter {
key = "hostname"
values = ["%s"]
}
}
`, name, name2, name)
}
2 changes: 1 addition & 1 deletion website/docs/d/instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data "civo_instances_size" "small" {
data "civo_instances" "small-with-backups" {
filter {
key = "size"
values = [data.civo_instances_size.small.sizes[1].name]
values = [element(data.civo_instances_size.small.sizes, 0).name]
}
sort {
key = "created_at"
Expand Down

0 comments on commit 4f3a1a1

Please sign in to comment.