-
Notifications
You must be signed in to change notification settings - Fork 54
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 instance test Fixed typo error in doc Signed-off-by: Alejandro JNM <[email protected]>
- Loading branch information
1 parent
12c41ce
commit 8b75b83
Showing
5 changed files
with
81 additions
and
6 deletions.
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,75 @@ | ||
package civo | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceCivoInstance_basic(t *testing.T) { | ||
datasourceName := "data.civo_instance.foobar" | ||
name := acctest.RandomWithPrefix("instance") + ".com" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceCivoInstanceConfig(name), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(datasourceName, "hostname", name), | ||
resource.TestCheckResourceAttrSet(datasourceName, "private_ip"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "public_ip"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "pseudo_ip"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceCivoInstanceByID_basic(t *testing.T) { | ||
datasourceName := "data.civo_instance.foobar" | ||
name := acctest.RandomWithPrefix("instance") + ".com" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceCivoInstanceByIDConfig(name), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(datasourceName, "hostname", name), | ||
resource.TestCheckResourceAttrSet(datasourceName, "private_ip"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "public_ip"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "pseudo_ip"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceCivoInstanceConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "civo_instance" "vm" { | ||
hostname = "%s" | ||
} | ||
data "civo_instance" "foobar" { | ||
hostname = civo_instance.vm.hostname | ||
} | ||
`, name) | ||
} | ||
|
||
func testAccDataSourceCivoInstanceByIDConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "civo_instance" "vm" { | ||
hostname = "%s" | ||
} | ||
data "civo_instance" "foobar" { | ||
id = civo_instance.vm.id | ||
} | ||
`, 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
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
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
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