Skip to content

Commit 952ce5b

Browse files
committed
fix(lint): resolve all 10 golangci-lint v2 issues
- errcheck: add _ = to io.Copy and w.Write return values (5 fixes) - staticcheck SA1012: nil context → context.TODO() in auth_test.go - staticcheck QF1003: if/else chain → tagged switch in filesystems_test.go - staticcheck SA4017: assert IsNull() return value instead of ignoring it - unused: remove fsType() and stateFromPlan() dead code
1 parent 11a21aa commit 952ce5b

6 files changed

Lines changed: 13 additions & 34 deletions

File tree

internal/client/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func LoginWithAPIToken(ctx context.Context, httpClient *http.Client, endpoint, a
3737
return "", fmt.Errorf("login: POST /api/login: %w", err)
3838
}
3939
defer resp.Body.Close()
40-
io.Copy(io.Discard, resp.Body)
40+
_, _ = io.Copy(io.Discard, resp.Body)
4141

4242
if resp.StatusCode != http.StatusOK {
4343
return "", fmt.Errorf("login: unexpected status %d", resp.StatusCode)

internal/client/auth_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client_test
22

33
import (
4+
"context"
45
"net/http"
56
"net/http/httptest"
67
"sync/atomic"
@@ -17,7 +18,7 @@ func TestUnit_OAuth2TokenSource(t *testing.T) {
1718
}
1819
w.Header().Set("Content-Type", "application/json")
1920
w.WriteHeader(http.StatusOK)
20-
w.Write([]byte(`{"access_token":"test-access-token","expires_in":3600,"token_type":"Bearer"}`))
21+
_, _ = w.Write([]byte(`{"access_token":"test-access-token","expires_in":3600,"token_type":"Bearer"}`))
2122
}))
2223
defer srv.Close()
2324

@@ -41,7 +42,7 @@ func TestUnit_OAuth2TokenSource_Caching(t *testing.T) {
4142
atomic.AddInt32(&callCount, 1)
4243
w.Header().Set("Content-Type", "application/json")
4344
w.WriteHeader(http.StatusOK)
44-
w.Write([]byte(`{"access_token":"cached-token","expires_in":3600,"token_type":"Bearer"}`))
45+
_, _ = w.Write([]byte(`{"access_token":"cached-token","expires_in":3600,"token_type":"Bearer"}`))
4546
}))
4647
defer srv.Close()
4748

@@ -76,7 +77,7 @@ func TestUnit_LoginWithAPIToken(t *testing.T) {
7677
}))
7778
defer srv.Close()
7879

79-
tok, err := client.LoginWithAPIToken(nil, srv.Client(), srv.URL, "my-api-token")
80+
tok, err := client.LoginWithAPIToken(context.TODO(), srv.Client(), srv.URL, "my-api-token")
8081
if err != nil {
8182
t.Fatalf("LoginWithAPIToken(): %v", err)
8283
}
@@ -89,7 +90,7 @@ func TestUnit_APIError_NotFound(t *testing.T) {
8990
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
9091
w.Header().Set("Content-Type", "application/json")
9192
w.WriteHeader(http.StatusNotFound)
92-
w.Write([]byte(`{"errors":[{"message":"file system not found"}]}`))
93+
_, _ = w.Write([]byte(`{"errors":[{"message":"file system not found"}]}`))
9394
}))
9495
defer srv.Close()
9596

internal/client/filesystems_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,20 +445,21 @@ func TestUnit_FileSystem_List_Paginated(t *testing.T) {
445445
case r.Method == http.MethodGet && r.URL.Path == "/api/2.22/file-systems":
446446
callCount++
447447
token := r.URL.Query().Get("continuation_token")
448-
if token == "" {
448+
switch token {
449+
case "":
449450
// First page: return 2 items + continuation_token.
450451
writeJSON(w, http.StatusOK, map[string]any{
451452
"items": page1,
452453
"total_item_count": 3,
453454
"continuation_token": "page2-token",
454455
})
455-
} else if token == "page2-token" {
456+
case "page2-token":
456457
// Second page: return 1 item, no token.
457458
writeJSON(w, http.StatusOK, map[string]any{
458459
"items": page2,
459460
"total_item_count": 3,
460461
})
461-
} else {
462+
default:
462463
http.Error(w, "unexpected continuation_token", http.StatusBadRequest)
463464
}
464465
default:

internal/client/transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (t *retryTransport) RoundTrip(req *http.Request) (*http.Response, error) {
7070

7171
// Drain and close the response body before retrying to release the
7272
// underlying TCP connection back to the pool.
73-
io.Copy(io.Discard, resp.Body)
73+
_, _ = io.Copy(io.Discard, resp.Body)
7474
resp.Body.Close()
7575

7676
delay := t.computeDelay(attempt)

internal/provider/filesystem_resource_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ func resourceSchema(t *testing.T) resource.SchemaResponse {
4242
return resp
4343
}
4444

45-
// fsType returns the tftypes.Object for the full filesystem resource schema.
46-
// It is built from the actual schema so tests stay in sync automatically.
47-
func fsType(t *testing.T) tftypes.Object {
48-
t.Helper()
49-
s := resourceSchema(t).Schema
50-
typ, err := s.Type().ApplyTerraform5AttributePathStep(nil)
51-
_ = typ
52-
_ = err
53-
// Build a static tftypes.Object matching the schema — maintained manually
54-
// but checked against the schema via compile-time model struct.
55-
return buildFSType()
56-
}
57-
5845
// buildFSType returns the tftypes.Object for filesystem_resource schema.
5946
func buildFSType() tftypes.Object {
6047
spaceType := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
@@ -203,16 +190,6 @@ func planWithName(t *testing.T, name string, provisioned int64) tfsdk.Plan {
203190
}
204191
}
205192

206-
// stateFromCreateResp builds a tfsdk.State from a Create response for Update/Delete tests.
207-
func stateFromPlan(t *testing.T, plan tfsdk.Plan) tfsdk.State {
208-
t.Helper()
209-
s := resourceSchema(t).Schema
210-
return tfsdk.State{
211-
Raw: plan.Raw,
212-
Schema: s,
213-
}
214-
}
215-
216193
// ---- tests ------------------------------------------------------------------
217194

218195
// TestUnit_FileSystem_Create verifies Create populates ID and computed fields.

internal/provider/object_store_access_policy_rule_resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ func TestObjectStoreAccessPolicyRuleResource_Create(t *testing.T) {
208208
if len(actions) != 2 {
209209
t.Errorf("expected 2 actions, got %d", len(actions))
210210
}
211-
if model.Conditions.IsNull() {
212-
// Expected null since no conditions provided
211+
if !model.Conditions.IsNull() {
212+
t.Error("expected conditions to be null since none were provided")
213213
}
214214
}
215215

0 commit comments

Comments
 (0)