-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the the test of dns domain name and dns domain record Fix the version of Go in the Readme
- Loading branch information
1 parent
2127d82
commit 400524a
Showing
7 changed files
with
273 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package civo | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceCivoDnsDomainName(t *testing.T) { | ||
datasourceName := "data.civo_dns_domain_name.domain" | ||
domain := acctest.RandomWithPrefix("domian") + ".com" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceCivoDNSDomainName(domain), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(datasourceName, "name", domain), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceCivoDNSDomainName(domain string) string { | ||
return fmt.Sprintf(` | ||
resource "civo_dns_domain_name" "domain" { | ||
name = "%[1]s" | ||
} | ||
data "civo_dns_domain_name" "domain" { | ||
name = civo_dns_domain_name.domain.name | ||
} | ||
`, domain) | ||
} |
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,53 @@ | ||
package civo | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceCivoDNSDomainRecord_basic(t *testing.T) { | ||
datasourceName := "data.civo_dns_domain_record.record" | ||
domain := acctest.RandomWithPrefix("recordtest") + ".com" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceCivoDNSDomainRecordConfigBasic(domain), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(datasourceName, "name", "www"), | ||
resource.TestCheckResourceAttr(datasourceName, "type", "a"), | ||
resource.TestCheckResourceAttr(datasourceName, "ttl", "600"), | ||
resource.TestCheckResourceAttr(datasourceName, "value", "192.168.1.1"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "id"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "domain_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceCivoDNSDomainRecordConfigBasic(domain string) string { | ||
return fmt.Sprintf(` | ||
resource "civo_dns_domain_name" "domain" { | ||
name = "%[1]s" | ||
} | ||
resource "civo_dns_domain_record" "record" { | ||
domain_id = civo_dns_domain_name.domain.id | ||
type = "a" | ||
name = "www" | ||
value = "192.168.1.1" | ||
ttl = 600 | ||
} | ||
data "civo_dns_domain_record" "record" { | ||
domain_id = civo_dns_domain_name.domain.id | ||
name = civo_dns_domain_record.record.name | ||
} | ||
`, domain) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package civo | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
var testAccProviders map[string]terraform.ResourceProvider | ||
var testAccProvider *schema.Provider | ||
|
||
func init() { | ||
testAccProvider = Provider().(*schema.Provider) | ||
testAccProviders = map[string]terraform.ResourceProvider{ | ||
"civo": testAccProvider, | ||
} | ||
} | ||
|
||
func TestProvider(t *testing.T) { | ||
if err := Provider().(*schema.Provider).InternalValidate(); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
func testAccPreCheck(t *testing.T) { | ||
if v := os.Getenv("CIVO_TOKEN"); v == "" { | ||
t.Fatal("CIVO_TOKEN must be set for acceptance tests") | ||
} | ||
} |
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,147 @@ | ||
package civo | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/civo/civogo" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
// example.Widget represents a concrete Go type that represents an API resource | ||
func TestAccCivoDNSDomainName_basic(t *testing.T) { | ||
var domain civogo.DNSDomain | ||
|
||
// generate a random name for each test run | ||
resName := "civo_dns_domain_name.foobar" | ||
var domainName = acctest.RandomWithPrefix("tf-test") + ".example" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckCivoDNSDomainNameDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
// use a dynamic configuration with the random name from above | ||
Config: testAccCheckCivoDNSDomainNameConfigBasic(domainName), | ||
// compose a basic test, checking both remote and local values | ||
Check: resource.ComposeTestCheckFunc( | ||
// query the API to retrieve the widget object | ||
testAccCheckCivoDNSDomainNameResourceExists(resName, &domain), | ||
// verify remote values | ||
testAccCheckCivoDNSDomainNameValues(&domain, domainName), | ||
// verify local values | ||
resource.TestCheckResourceAttr(resName, "name", domainName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccCivoDNSDomainName_update(t *testing.T) { | ||
var domain civogo.DNSDomain | ||
|
||
// generate a random name for each test run | ||
resName := "civo_dns_domain_name.foobar" | ||
var domainName = acctest.RandomWithPrefix("renamed-tf-test") + ".example" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckCivoDNSDomainNameDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckCivoDNSDomainNameConfigUpdates(domainName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCivoDNSDomainNameResourceExists(resName, &domain), | ||
testAccCheckCivoDNSDomainNameValues(&domain, domainName), | ||
resource.TestCheckResourceAttr(resName, "name", domainName), | ||
), | ||
}, | ||
{ | ||
// use a dynamic configuration with the random name from above | ||
Config: testAccCheckCivoDNSDomainNameConfigUpdates(domainName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCivoDNSDomainNameResourceExists(resName, &domain), | ||
testAccCheckCivoDNSDomainNameUpdated(&domain, domainName), | ||
resource.TestCheckResourceAttr(resName, "name", domainName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckCivoDNSDomainNameValues(domain *civogo.DNSDomain, name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
if domain.Name != name { | ||
return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, domain.Name) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// testAccCheckExampleResourceExists queries the API and retrieves the matching Widget. | ||
func testAccCheckCivoDNSDomainNameResourceExists(n string, domain *civogo.DNSDomain) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
// find the corresponding state object | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
// retrieve the configured client from the test setup | ||
client := testAccProvider.Meta().(*civogo.Client) | ||
resp, err := client.FindDNSDomain(rs.Primary.ID) | ||
if err != nil { | ||
return fmt.Errorf("Domain not found: (%s) %s", rs.Primary.ID, err) | ||
} | ||
|
||
// If no error, assign the response Widget attribute to the widget pointer | ||
*domain = *resp | ||
|
||
// return fmt.Errorf("Domain (%s) not found", rs.Primary.ID) | ||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckCivoDNSDomainNameUpdated(domain *civogo.DNSDomain, name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
if domain.Name != name { | ||
return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, domain.Name) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckCivoDNSDomainNameDestroy(s *terraform.State) error { | ||
client := testAccProvider.Meta().(*civogo.Client) | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "civo_dns_domain_name" { | ||
continue | ||
} | ||
|
||
_, err := client.FindDNSDomain(rs.Primary.ID) | ||
if err == nil { | ||
return fmt.Errorf("Domain still exists") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckCivoDNSDomainNameConfigBasic(domain string) string { | ||
return fmt.Sprintf(` | ||
resource "civo_dns_domain_name" "foobar" { | ||
name = "%s" | ||
}`, domain) | ||
} | ||
|
||
func testAccCheckCivoDNSDomainNameConfigUpdates(domain string) string { | ||
return fmt.Sprintf(` | ||
resource "civo_dns_domain_name" "foobar" { | ||
name = "%s" | ||
}`, domain) | ||
} |