Archived
Harden read-only provider with tests, docs, and CI
This commit is contained in:
1 parent
cf47a6ed48
commit
6cc1b206dc
24 files changed
+711
-246
No files matched your search
@@ -1,18 +1,77 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/dynu/terraform-provider-dynu/internal/dynuclient"
|
||||
)
|
||||
|
||||
func TestAccScaffold(t *testing.T) {
|
||||
if os.Getenv("TF_ACC") != "1" || os.Getenv("DYNU_API_KEY") == "" {
|
||||
t.Skip("set TF_ACC=1 and DYNU_API_KEY to enable acceptance tests")
|
||||
func testAccPreCheck(t *testing.T) {
|
||||
t.Helper()
|
||||
if os.Getenv("TF_ACC") != "1" {
|
||||
t.Skip("set TF_ACC=1 to run acceptance tests")
|
||||
}
|
||||
if os.Getenv("DYNU_API_KEY") == "" {
|
||||
t.Skip("set DYNU_API_KEY to run acceptance tests")
|
||||
}
|
||||
}
|
||||
|
||||
func testAccDomainFromEnv(t *testing.T) string {
|
||||
t.Helper()
|
||||
domain := os.Getenv("DYNU_DOMAIN")
|
||||
if domain == "" {
|
||||
t.Skip("set DYNU_DOMAIN to run domain-specific acceptance tests")
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
||||
func TestAccDataSourceDomains(t *testing.T) {
|
||||
testAccPreCheck(t)
|
||||
|
||||
client := dynuclient.New(os.Getenv("DYNU_API_KEY"))
|
||||
domains, err := client.ListDomains(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("ListDomains() failed: %v", err)
|
||||
}
|
||||
if len(domains) == 0 {
|
||||
t.Fatal("expected at least one domain")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccDataSourceDomain(t *testing.T) {
|
||||
testAccPreCheck(t)
|
||||
hostname := testAccDomainFromEnv(t)
|
||||
|
||||
client := dynuclient.New(os.Getenv("DYNU_API_KEY"))
|
||||
domainID, _, err := client.GetRootDomain(context.Background(), hostname)
|
||||
if err != nil {
|
||||
t.Fatalf("GetRootDomain() failed: %v", err)
|
||||
}
|
||||
domain, err := client.GetDomainByID(context.Background(), domainID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetDomainByID() failed: %v", err)
|
||||
}
|
||||
if domain.ID == 0 || domain.Name == "" {
|
||||
t.Fatalf("unexpected domain payload: %#v", domain)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccDataSourceDNSRecords(t *testing.T) {
|
||||
testAccPreCheck(t)
|
||||
hostname := testAccDomainFromEnv(t)
|
||||
|
||||
client := dynuclient.New(os.Getenv("DYNU_API_KEY"))
|
||||
domainID, _, err := client.GetRootDomain(context.Background(), hostname)
|
||||
if err != nil {
|
||||
t.Fatalf("GetRootDomain() failed: %v", err)
|
||||
}
|
||||
records, err := client.ListDNSRecords(context.Background(), domainID)
|
||||
if err != nil {
|
||||
t.Fatalf("ListDNSRecords() failed: %v", err)
|
||||
}
|
||||
if records == nil {
|
||||
t.Fatal("expected records slice, got nil")
|
||||
}
|
||||
|
||||
// Optional: DYNU_DOMAIN may be used by future acceptance test cases.
|
||||
_ = os.Getenv("DYNU_DOMAIN")
|
||||
|
||||
// Acceptance tests for read-only data sources are intentionally scaffolded in phase 1.
|
||||
// Add terraform-plugin-testing based test cases in a follow-up with stable fixtures.
|
||||
}
|
||||
Reference in new issue
Block a user