Add mock-backed integration testing tier and fake Dynu API

This commit is contained in:
beatz174-bit committed 2026-04-21 15:19:20 +10:00
1 parent 7f161fb19b
commit 293fe7af28
10 files changed
+564 -154

No files matched your search

+10 -5
View File
@@ -73,18 +73,20 @@ func (d *domainDataSource) Configure(_ context.Context, req datasource.Configure
}
func (d *domainDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var state domainDataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
var config struct {
Hostname types.String `tfsdk:"hostname"`
}
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
}
if state.Hostname.IsUnknown() || state.Hostname.IsNull() {
if config.Hostname.IsUnknown() || config.Hostname.IsNull() {
resp.Diagnostics.AddAttributeError(path.Root("hostname"), "Invalid hostname", "The hostname must be known and non-null.")
return
}
domainID, _, err := d.clientProvider.client.GetRootDomain(ctx, state.Hostname.ValueString())
domainID, _, err := d.clientProvider.client.GetRootDomain(ctx, config.Hostname.ValueString())
if err != nil {
resp.Diagnostics.AddError("Unable to resolve Dynu domain from hostname", err.Error())
return
@@ -101,7 +103,10 @@ func (d *domainDataSource) Read(ctx context.Context, req datasource.ReadRequest,
if resp.Diagnostics.HasError() {
return
}
state.Domain = domainObject
state := domainDataSourceModel{
Hostname: config.Hostname,
Domain: domainObject,
}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}