Archived
ci / test (push) Failing after 5m55s
- DYNU_API_KEY env var fallback in provider config - dynu_domain resource: add 9 computed attributes (unicode_name, ipv4/ipv6 flags, wildcard aliases, allow_zone_transfer, dnssec, created_on, updated_on) - dynu_dns_records data source: add 6 type-specific fields (priority, weight, port, flags, tag, value) - Fix normalizeRecordContentForState for MX/SRV/NS/PTR (read host field) and CAA (read value field) to avoid plan/state inconsistency - Allow underscore-prefixed DNS labels in hostname validator (RFC 2782 SRV) - Preserve plan/state hostname across create/update/read to prevent inconsistent result errors when API returns full FQDN for node_name-style records - Update all version references from 0.1.0 to 0.2.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LFZyrmtKsezBwFWGTWsb2y
67 lines
2.5 KiB
Go
67 lines
2.5 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/beatz174-bit/terraform-provider-dynu/internal/testutil/fakedynu"
|
|
"github.com/hashicorp/terraform-plugin-framework/path"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
|
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
)
|
|
|
|
func TestIntegrationResourceDomainLifecycleAndImport(t *testing.T) {
|
|
ctx := context.Background()
|
|
fake := fakedynu.NewServer()
|
|
defer fake.Close()
|
|
r := NewDomainResource().(*domainResource)
|
|
configureResource(t, r, fake.BaseURL())
|
|
var schemaResp resource.SchemaResponse
|
|
r.Schema(ctx, resource.SchemaRequest{}, &schemaResp)
|
|
|
|
planModel := domainResourceModel{Name: types.StringValue("new.example.com"), TTL: types.Int64Value(120), IPv4Address: types.StringValue("203.0.113.7")}
|
|
plan := tfsdk.Plan{Schema: schemaResp.Schema}
|
|
_ = plan.Set(ctx, &planModel)
|
|
createResp := resource.CreateResponse{State: tfsdk.State{Schema: schemaResp.Schema}}
|
|
r.Create(ctx, resource.CreateRequest{Plan: plan}, &createResp)
|
|
if createResp.Diagnostics.HasError() {
|
|
t.Fatalf("create diagnostics: %v", createResp.Diagnostics)
|
|
}
|
|
|
|
var state domainResourceModel
|
|
_ = createResp.State.Get(ctx, &state)
|
|
if state.ID.ValueInt64() == 0 {
|
|
t.Fatal("expected created id")
|
|
}
|
|
if state.State.IsNull() || state.State.IsUnknown() {
|
|
t.Fatal("expected state attribute to be populated after create")
|
|
}
|
|
if state.UnicodeName.IsNull() || state.UnicodeName.IsUnknown() {
|
|
t.Fatal("expected unicode_name to be populated after create")
|
|
}
|
|
if state.DNSSEC.IsNull() || state.DNSSEC.IsUnknown() {
|
|
t.Fatal("expected dnssec to be a known bool after create")
|
|
}
|
|
|
|
state.TTL = types.Int64Value(300)
|
|
plan = tfsdk.Plan{Schema: schemaResp.Schema}
|
|
_ = plan.Set(ctx, &state)
|
|
updateResp := resource.UpdateResponse{State: tfsdk.State{Schema: schemaResp.Schema}}
|
|
r.Update(ctx, resource.UpdateRequest{Plan: plan, State: createResp.State}, &updateResp)
|
|
if updateResp.Diagnostics.HasError() {
|
|
t.Fatalf("update diagnostics: %v", updateResp.Diagnostics)
|
|
}
|
|
|
|
importResp := resource.ImportStateResponse{State: tfsdk.State{Schema: schemaResp.Schema}}
|
|
r.ImportState(ctx, resource.ImportStateRequest{ID: "5002"}, &importResp)
|
|
if importResp.Diagnostics.HasError() {
|
|
t.Fatalf("import diagnostics: %v", importResp.Diagnostics)
|
|
}
|
|
var imported int64
|
|
_ = importResp.State.GetAttribute(ctx, path.Root("id"), &imported)
|
|
if imported != 5002 {
|
|
t.Fatalf("unexpected imported id %d", imported)
|
|
}
|
|
}
|