Archived
Merge pull request #33 from beatz174-bit/codex/investigate-blank-a-record-issue
Treat API 505 validation errors as unsupported empty content and add unit tests
This commit is contained in:
@@ -539,7 +539,10 @@ func normalizeRecordContentForState(recordType string, content string, dynamicIn
|
||||
|
||||
func isUnsupportedEmptyContentError(err error) bool {
|
||||
var apiErr *dynuclient.APIError
|
||||
if !errors.As(err, &apiErr) || apiErr.StatusCode != 400 {
|
||||
if !errors.As(err, &apiErr) {
|
||||
return false
|
||||
}
|
||||
if apiErr.StatusCode != 400 && apiErr.StatusCode != 505 {
|
||||
return false
|
||||
}
|
||||
normalizedType := strings.ToLower(strings.TrimSpace(apiErr.Type))
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/dynu/terraform-provider-dynu/internal/dynuclient"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
@@ -191,3 +192,56 @@ func TestInferDynamicIntentFromState(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsUnsupportedEmptyContentError(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "status 400 content required",
|
||||
err: &dynuclient.APIError{
|
||||
StatusCode: 400,
|
||||
Type: "Validation Exception",
|
||||
Message: "content is required",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "status 505 invalid ip address",
|
||||
err: &dynuclient.APIError{
|
||||
StatusCode: 505,
|
||||
Type: "Validation Exception",
|
||||
Message: "Invalid IP address.",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "status 505 unrelated message",
|
||||
err: &dynuclient.APIError{
|
||||
StatusCode: 505,
|
||||
Type: "Validation Exception",
|
||||
Message: "Some other validation failure",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "non validation exception",
|
||||
err: &dynuclient.APIError{
|
||||
StatusCode: 505,
|
||||
Type: "Unauthorized",
|
||||
Message: "Invalid IP address.",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := isUnsupportedEmptyContentError(tc.err); got != tc.want {
|
||||
t.Fatalf("isUnsupportedEmptyContentError()=%v, want %v", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user