Skip to content

Commit 5683ed2

Browse files
committed
fix: resolve golangci-lint issues
- Add error handling for resp.Body.Close() in client.go - Fix gofmt formatting in main.go - Optimize regexp compilation in resource_user_test.go - Remove unnecessary type assertion in metadata_test.go - Remove unused test functions in resource_client_test.go
1 parent 733930c commit 5683ed2

5 files changed

Lines changed: 14 additions & 40 deletions

File tree

internal/client/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ func (c *Client) doSingleRequest(ctx context.Context, method, endpoint string, b
213213
})
214214
return nil, fmt.Errorf("error making request: %w", err)
215215
}
216-
defer resp.Body.Close()
216+
defer func() {
217+
if err := resp.Body.Close(); err != nil {
218+
tflog.Warn(ctx, "Failed to close response body", map[string]interface{}{
219+
"error": err.Error(),
220+
})
221+
}
222+
}()
217223

218224
respBody, err := io.ReadAll(resp.Body)
219225
if err != nil {

internal/provider/resource_client_test.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010

1111
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12-
"github.com/hashicorp/terraform-plugin-testing/terraform"
1312
)
1413

1514
func TestAccResourceClient_basic(t *testing.T) {
@@ -179,7 +178,7 @@ func TestAccResourceClient_emptyName(t *testing.T) {
179178
// Test configuration functions
180179

181180
func testAccResourceClientConfig_basic(name, callbackURL string) string {
182-
return fmt.Sprintf(`
181+
return testAccProviderConfig() + fmt.Sprintf(`
183182
resource "pocketid_client" "test" {
184183
name = %[1]q
185184
callback_urls = [%[2]q]
@@ -188,7 +187,7 @@ resource "pocketid_client" "test" {
188187
}
189188

190189
func testAccResourceClientConfig_public(name string) string {
191-
return fmt.Sprintf(`
190+
return testAccProviderConfig() + fmt.Sprintf(`
192191
resource "pocketid_client" "test" {
193192
name = %[1]q
194193
callback_urls = ["https://example.com/callback"]
@@ -267,34 +266,3 @@ resource "pocketid_client" "test" {
267266
}
268267

269268
// Test helper functions
270-
271-
func testAccCheckClientExists(resourceName string) resource.TestCheckFunc {
272-
return func(s *terraform.State) error {
273-
rs, ok := s.RootModule().Resources[resourceName]
274-
if !ok {
275-
return fmt.Errorf("Not found: %s", resourceName)
276-
}
277-
278-
if rs.Primary.ID == "" {
279-
return fmt.Errorf("No Client ID is set")
280-
}
281-
282-
// Here you would typically check if the client exists in the API
283-
// For now, we just verify the ID is set
284-
return nil
285-
}
286-
}
287-
288-
func testAccCheckClientDestroy(s *terraform.State) error {
289-
// This function should check that all clients have been destroyed
290-
for _, rs := range s.RootModule().Resources {
291-
if rs.Type != "pocketid_client" {
292-
continue
293-
}
294-
295-
// Here you would typically check if the client still exists in the API
296-
// and return an error if it does
297-
}
298-
299-
return nil
300-
}

internal/provider/resource_user_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ func testAccCheckUserGroupsSet(resourceName string) resource.TestCheckFunc {
126126
// Get all group attributes
127127
groupCount := 0
128128
groups := make(map[string]bool)
129+
groupsRegex := regexp.MustCompile(`^groups\.\d+$`)
129130
for key, value := range rs.Primary.Attributes {
130-
if matched, _ := regexp.MatchString(`^groups\.\d+$`, key); matched {
131+
if groupsRegex.MatchString(key) {
131132
groups[value] = true
132133
groupCount++
133134
}

internal/resources/metadata_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,10 @@ func TestResources_Interfaces(t *testing.T) {
255255
t.Run(rf.name, func(t *testing.T) {
256256
res := rf.factory()
257257

258-
// Check implements Resource interface
259-
_, ok := res.(resource.Resource)
260-
assert.True(t, ok, "%s should implement resource.Resource", rf.name)
258+
// res is already of type resource.Resource, no need to check
261259

262260
// Check implements ResourceWithConfigure
263-
_, ok = res.(resource.ResourceWithConfigure)
261+
_, ok := res.(resource.ResourceWithConfigure)
264262
assert.True(t, ok, "%s should implement resource.ResourceWithConfigure", rf.name)
265263

266264
// Check implements ResourceWithImportState

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77

88
"github.com/hashicorp/terraform-plugin-framework/providerserver"
9+
910
"github.com/Trozz/terraform-provider-pocketid/internal/provider"
1011
)
1112

0 commit comments

Comments
 (0)