-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
834a4e3
commit 4f3a1a1
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters