Skip to content

Commit 3ff473d

Browse files
committed
probable fixes
1 parent d514fbe commit 3ff473d

File tree

6 files changed

+663
-46
lines changed

6 files changed

+663
-46
lines changed

internal/provider/resourceconfiguration/json_semantic_equals.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,3 @@ func jsonContains(container, subset interface{}) bool {
9999
func JSONSemanticEquals() planmodifier.String {
100100
return jsonSemanticEqualsPlanModifier{}
101101
}
102-

internal/provider/resourceconfiguration/resource.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ func (r *resourceConfigurationResource) Read(ctx context.Context, req resource.R
217217
// even though the API returns one. We need to make a raw HTTP call and parse it manually.
218218
// The actual API response format is identical for GET, POST, and PATCH operations.
219219

220-
// Get the API client configuration to make a raw HTTP request
220+
// Get the API client configuration to make a raw HTTP request.
221221
cfg := r.client.GetConfig()
222222

223-
// Construct the full URL using the host and scheme from the configuration
223+
// Construct the full URL using the host and scheme from the configuration.
224224
url := fmt.Sprintf("%s://%s/api/v2/resource_configurations/%s", cfg.Scheme, cfg.Host, configID)
225225
httpReq, err := http.NewRequestWithContext(ctx, "GET", url, nil)
226226
if err != nil {
@@ -231,13 +231,13 @@ func (r *resourceConfigurationResource) Read(ctx context.Context, req resource.R
231231
return
232232
}
233233

234-
// Add authentication and other headers
234+
// Add authentication and other headers.
235235
for key, value := range cfg.DefaultHeader {
236236
httpReq.Header.Set(key, value)
237237
}
238238
httpReq.Header.Set("Accept", "application/json")
239239

240-
// Execute the request using the client's HTTP client
240+
// Execute the request using the client's HTTP client.
241241
httpResponse, err := cfg.HTTPClient.Do(httpReq)
242242
if err != nil {
243243
resp.Diagnostics.AddError(
@@ -246,7 +246,7 @@ func (r *resourceConfigurationResource) Read(ctx context.Context, req resource.R
246246
)
247247
return
248248
}
249-
defer httpResponse.Body.Close()
249+
defer func() { _ = httpResponse.Body.Close() }()
250250

251251
// Handle 404
252252
if httpResponse.StatusCode == 404 {
@@ -274,7 +274,7 @@ func (r *resourceConfigurationResource) Read(ctx context.Context, req resource.R
274274
return
275275
}
276276

277-
// Parse the response using the correct Post200Response type (which has .Data wrapper)
277+
// Parse the response using the correct Post200Response type (which has .Data wrapper).
278278
var configuration api.ResourceConfigurationsPost200Response
279279
if err := json.Unmarshal(bodyBytes, &configuration); err != nil {
280280
resp.Diagnostics.AddError(
@@ -377,10 +377,10 @@ func (r *resourceConfigurationResource) Update(ctx context.Context, req resource
377377
plan.CreatedAt = types.StringValue(updateResponse.Data.CreatedAt)
378378
plan.UpdatedAt = types.StringValue(updateResponse.Data.UpdatedAt)
379379

380-
// Note: We don't update options from the API response because:
381-
// 1. The API adds default values that weren't in the plan
382-
// 2. This would cause Terraform to see inconsistent values for sensitive attributes
383-
// Instead, we keep the planned value which is what the user specified
380+
// Note: We don't update options from the API response because:.
381+
// 1. The API adds default values that weren't in the plan.
382+
// 2. This would cause Terraform to see inconsistent values for sensitive attributes.
383+
// Instead, we keep the planned value which is what the user specified.
384384

385385
diags = resp.State.Set(ctx, plan)
386386
resp.Diagnostics.Append(diags...)
Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
package resourceconfiguration_test
1+
package resourceconfiguration
22

33
import (
4+
"context"
45
"testing"
56

6-
"github.com/hashicorp/terraform-plugin-framework/providerserver"
7-
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
8-
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9-
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
10-
"github.com/hashicorp/terraform-plugin-testing/statecheck"
11-
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
12-
13-
"github.com/tryretool/terraform-provider-retool/internal/provider"
7+
// The fwresource import alias is so there is no collision
8+
// with the more typical acceptance testing import:
9+
// "github.com/hashicorp/terraform-plugin-testing/helper/resource".
10+
fwresource "github.com/hashicorp/terraform-plugin-framework/resource"
1411
)
1512

16-
// TestAccResourceConfigurationResourceSchema tests the resource schema for the resource configuration resource.
17-
func TestAccResourceConfigurationResourceSchema(t *testing.T) {
18-
resource.Test(t, resource.TestCase{
19-
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
20-
"retool": providerserver.NewProtocol6WithError(provider.New("test")()),
21-
},
22-
Steps: []resource.TestStep{
23-
{
24-
Config: `
25-
resource "retool_resource_configuration" "test" {
26-
resource_id = "00000000-0000-0000-0000-000000000000"
27-
environment_id = "00000000-0000-0000-0000-000000000000"
28-
options = jsonencode({
29-
base_url = "https://api.example.com"
30-
})
31-
}
32-
`,
33-
ConfigStateChecks: []statecheck.StateCheck{
34-
statecheck.ExpectKnownValue("retool_resource_configuration.test", tfjsonpath.New("resource_id"), knownvalue.StringExact("00000000-0000-0000-0000-000000000000")),
35-
statecheck.ExpectKnownValue("retool_resource_configuration.test", tfjsonpath.New("environment_id"), knownvalue.StringExact("00000000-0000-0000-0000-000000000000")),
36-
},
37-
},
38-
},
39-
})
40-
}
13+
func TestResourceConfigurationResourceSchema(t *testing.T) {
14+
t.Parallel()
15+
16+
ctx := context.Background()
17+
schemaRequest := fwresource.SchemaRequest{}
18+
schemaResponse := &fwresource.SchemaResponse{}
19+
20+
// Instantiate the resource.Resource and call its Schema method.
21+
NewResource().Schema(ctx, schemaRequest, schemaResponse)
4122

23+
if schemaResponse.Diagnostics.HasError() {
24+
t.Fatalf("Schema method diagnostics: %+v", schemaResponse.Diagnostics)
25+
}
26+
27+
// Validate the schema.
28+
diagnostics := schemaResponse.Schema.ValidateImplementation(ctx)
29+
30+
if diagnostics.HasError() {
31+
t.Fatalf("Schema validation diagnostics: %+v", diagnostics)
32+
}
33+
}

internal/provider/resourceconfiguration/resource_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,3 @@ func init() {
136136
},
137137
})
138138
}
139-

terraform-provider-retool

86.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)