Skip to content

Commit 62a2def

Browse files
Copilotmawasilemattdot
authored
Fix type safety and formatting issues in provider code (#844)
* Initial plan for issue * Fix Issue 1: Add string length validation to billing policy required fields Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com> * Fix Issue 2: Update UrlFormatError to use pointer receiver for future-proofing Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com> * Fix Issue 3: Fix escaped newlines in UUID error message constants Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com> * Add changelog entry for type safety and formatting fixes Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com> Co-authored-by: Matt Dotson <mattdot@users.noreply.github.com>
1 parent 67a70d1 commit 62a2def

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kind: fixed
2+
body: Fixed type safety and formatting issues including missing string validation, interface assertions, and escaped newline formatting
3+
custom:
4+
Issue: 825

internal/api/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func TestUnitApiClient_GetConfig(t *testing.T) {
3939
}
4040

4141
switch err.(type) {
42-
case customerrors.UrlFormatError:
42+
case *customerrors.UrlFormatError:
4343
return
4444
default:
45-
t.Errorf("Expected error type %s but got %s", reflect.TypeOf(customerrors.UrlFormatError{}), reflect.TypeOf(err))
45+
t.Errorf("Expected error type %s but got %s", reflect.TypeOf(&customerrors.UrlFormatError{}), reflect.TypeOf(err))
4646
}
4747
}
4848

internal/customerrors/url_format_error.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import (
77
"fmt"
88
)
99

10-
var _ error = UrlFormatError{}
10+
var _ error = (*UrlFormatError)(nil)
1111

1212
type UrlFormatError struct {
1313
Url string
1414
Err error
1515
}
1616

1717
func NewUrlFormatError(url string, err error) error {
18-
return UrlFormatError{
18+
return &UrlFormatError{
1919
Err: err,
2020
Url: url,
2121
}
2222
}
2323

24-
func (e UrlFormatError) Error() string {
24+
func (e *UrlFormatError) Error() string {
2525
errorMsg := ""
2626
if e.Err != nil {
2727
errorMsg = e.Err.Error()
@@ -30,6 +30,6 @@ func (e UrlFormatError) Error() string {
3030
return fmt.Sprintf("Request url must be an absolute url: '%s' : '%s'", e.Url, errorMsg)
3131
}
3232

33-
func (e UrlFormatError) Unwrap() error {
33+
func (e *UrlFormatError) Unwrap() error {
3434
return e.Err
3535
}

internal/customtypes/uuid_value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
const (
2020
UUIDTypeErrorInvalidStringHeader = "Invalid UUID String Value"
21-
UUIDTypeErrorInvalidStringDetails = `A string value was provided that is not valid UUID string format.\n\nGiven Value: %s\n`
21+
UUIDTypeErrorInvalidStringDetails = "A string value was provided that is not valid UUID string format.\n\nGiven Value: %s\n"
2222
)
2323

2424
var (

internal/services/licensing/resource_billing_policy.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ func (r *BillingPolicyResource) Schema(ctx context.Context, req resource.SchemaR
6868
"name": schema.StringAttribute{
6969
MarkdownDescription: "The name of the billing policy",
7070
Required: true,
71+
Validators: []validator.String{
72+
stringvalidator.LengthAtLeast(1),
73+
},
7174
},
7275
"location": schema.StringAttribute{
7376
MarkdownDescription: "The location of the billing policy",
7477
Required: true,
78+
Validators: []validator.String{
79+
stringvalidator.LengthAtLeast(1),
80+
},
7581
PlanModifiers: []planmodifier.String{
7682
stringplanmodifier.RequiresReplace(),
7783
},
@@ -98,13 +104,19 @@ func (r *BillingPolicyResource) Schema(ctx context.Context, req resource.SchemaR
98104
"resource_group": schema.StringAttribute{
99105
MarkdownDescription: "The resource group of the billing instrument",
100106
Required: true,
107+
Validators: []validator.String{
108+
stringvalidator.LengthAtLeast(1),
109+
},
101110
PlanModifiers: []planmodifier.String{
102111
stringplanmodifier.RequiresReplace(),
103112
},
104113
},
105114
"subscription_id": schema.StringAttribute{
106115
MarkdownDescription: "The subscription id of the billing instrument",
107116
Required: true,
117+
Validators: []validator.String{
118+
stringvalidator.LengthAtLeast(1),
119+
},
108120
PlanModifiers: []planmodifier.String{
109121
stringplanmodifier.RequiresReplace(),
110122
},

0 commit comments

Comments
 (0)