Add acceptance tests for DNS record resource and data source #35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "13-acceptance-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds provider-level acceptance tests using
terraform-plugin-testingto verify the full plan/apply/destroy lifecycle forgodaddy_dns_recordresource andgodaddy_dns_recordsdata source against the live GoDaddy API.Changes
provider_test.go-- shared test infrastructure: ProtoV6 provider factory map,testAccPreCheckandtestAccPreCheckWithDomainhelpers checking required env varsresource_dns_record_test.go-- DNS record resource CRUD lifecycle test: create A record with_test-basicprefix, verify all attributes viastatecheck.ExpectKnownValue, update TTL and verify, import via composite IDdomain:A:name,CheckDestroycalling GoDaddy API directly to confirm deletiondata_source_dns_records_test.go-- DNS records data source test: creates a test record then reads it back via data source filtered by type and name, verifies computed ID and records list sizego.mod/go.sum-- addsgithub.com/hashicorp/terraform-plugin-testingv1.16.0 dependencyTest Plan
go build ./...-- passes (compile check)go vet ./...-- passes (static analysis)TF_ACC=1 GODADDY_API_KEY=... GODADDY_API_SECRET=... GODADDY_TEST_DOMAIN=... go test ./... -v-- runs full acceptance suite (requires live API credentials)_test-prefix names for isolation from production recordsCheckDestroyconfirms records are deleted after each testReview Checklist
go build ./...passesgo vet ./...passes_test-prefix namesTF_ACC=1Related Notes
PR #35 Review
DOMAIN REVIEW
Tech stack: Go / Terraform Plugin Framework / terraform-plugin-testing v1.16.0
This PR adds acceptance tests for the
godaddy_dns_recordresource andgodaddy_dns_recordsdata source. Three new test files follow the canonical pattern for Plugin Framework provider acceptance testing.Provider factory (
provider_test.go:15):The PR uses
New("test")()which is correct --Newreturnsfunc() provider.Provider, so calling it twice (once to get the factory, once to invoke it) produces theprovider.Providervalue thatNewProtocol6WithErrorexpects. Note thatdocs/conventions.mdline 129 showsNew("test")(without the second invocation), which would fail to compile due to type mismatch. The conventions doc should be corrected in a follow-up, but the PR code is right.Test coverage analysis:
CheckDestroycalls GoDaddy API directly to confirm deletiondomain:A:_test-basic, verifies full state round-tripstatecheck usage: All assertions use the modern
statecheck.ExpectKnownValue+knownvalue+tfjsonpathAPI per conventions. No deprecatedresource.TestCheckResourceAttrusage.CheckDestroy (
resource_dns_record_test.go:74-101): Correctly creates a direct API client with env var credentials and queries GoDaddy for eachgodaddy_dns_recordresource in state. API errors (including 404) are treated as successful destruction. Non-empty record list returns an error. This matches the conventions doc pattern exactly.Data source test (
data_source_dns_records_test.go): Self-contained -- creates a resource first, then reads it back via the data source withdepends_on. Verifies computed ID format and list size. Good isolation.Test record naming:
_test-basicand_test-dsprefixes follow the_test-naming convention for test isolation.HCL configs: All configs use empty
provider "godaddy" {}blocks (auth via env vars) per conventions.IP addresses: Tests use
192.0.2.1and192.0.2.2which are in RFC 5737 TEST-NET-1 range -- good practice for test fixtures.go.mod:
terraform-plugin-testingv1.16.0 added as a direct dependency.terraform-plugin-gov0.31.0 promoted from indirect to direct (needed fortfprotov6type inprovider_test.go). All other additions are transitive indirect dependencies.BLOCKERS
None.
NITS
Conventions doc drift (non-blocking, track separately):
docs/conventions.mdline 129 showsproviderserver.NewProtocol6WithError(New("test"))but this would not compile. The correct invocation isNew("test")()as the PR implements. Consider a follow-up fix to the conventions doc so future contributors are not confused.Data source test does not verify individual record attributes:
TestAccDNSRecords_basicchecks theidformat andrecordslist size, but does not assert on the actual record content within the list (e.g., data, TTL). Consider adding aknownvalue.ListExactor index-based path check onrecords[0].datato verify the data source maps fields correctly. This is not a blocker because the resource test already validates the underlying CRUD, but it would strengthen data source-specific coverage.No negative/edge-case test for invalid domain: An optional improvement would be a test that verifies provider error handling when given a nonexistent domain. Not required for the initial acceptance test suite.
PreCheck message wording inconsistency:
testAccPreCheckuses "must be set for acceptance tests" while the conventions doc example shows just "must be set". The PR version is actually more informative -- the conventions doc could be updated to match.SOP COMPLIANCE
.envfiles, or credentials committedGODADDY_TEST_DOMAINenv varTF_ACC=1(handled automatically byresource.Test)PROCESS OBSERVATIONS
pkg/godaddy/*_test.go) and provider-level acceptance tests.New("test")vsNew("test")()) should be tracked as a follow-up to prevent confusion.VERDICT: APPROVED