Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ linters:
- path: ^internal/goclusterfs/
linters: [errcheck]

- path: ^cmd/gfsctl/
linters: [errcheck]

- path: ^cmd/mount/
linters: [errcheck]

Expand All @@ -41,6 +38,10 @@ linters:
- path: ^tests/integration/
linters: [errcheck]

# gfsctl prints to the terminal and, like fmt.Printf, ignores write errors there.
- path: ^cmd/gfsctl/
linters: [errcheck]
text: "`fmt\\.Fprint(f|ln)?` is not checked"
- path: ^internal/goclusterfs/fs\.go$
linters: [unused]
text: "errRetryCreate|field sb is unused"
Expand Down
2 changes: 1 addition & 1 deletion cmd/gfsctl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *Client) send(ctx context.Context, method, path string) ([]byte, int, er
logging.Debugf("%s %s failed after %v: %v", method, url, time.Since(start).Round(time.Millisecond), err)
return nil, 0, fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

body, err := io.ReadAll(io.LimitReader(resp.Body, MaxResponseSize+1))
logging.Debugf("%s %s: %s, %d bytes in %v", method, url, resp.Status, len(body), time.Since(start).Round(time.Millisecond))
Expand Down
4 changes: 2 additions & 2 deletions cmd/gfsctl/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func TestAPIErrorCarriesStatusAndDetails(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Bearer secret" {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"error":"invalid token","code":401}`))
_, _ = w.Write([]byte(`{"error":"invalid token","code":401}`))
return
}
w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("not json"))
_, _ = w.Write([]byte("not json"))
}))
defer srv.Close()
c := &Client{baseURL: srv.URL, httpClient: srv.Client()}
Expand Down
25 changes: 16 additions & 9 deletions cmd/gfsctl/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -25,12 +26,16 @@ func TestMain(m *testing.M) {
if err != nil {
panic(err)
}
os.Setenv("XDG_CONFIG_HOME", dir)
if err := os.Setenv("XDG_CONFIG_HOME", dir); err != nil {
panic(err)
}
for _, name := range []string{"GFSCTL_HOST", "GFSCTL_PORT", "GFSCTL_TOKEN", "GFSCTL_OUTPUT", "GFSCTL_TIMEOUT", "NO_COLOR"} {
os.Unsetenv(name)
if err := os.Unsetenv(name); err != nil {
panic(err)
}
}
code := m.Run()
os.RemoveAll(dir)
_ = os.RemoveAll(dir)
os.Exit(code)
}

Expand Down Expand Up @@ -63,11 +68,11 @@ func startFakeAPI(t *testing.T, routes map[string]any) *fakeAPI {
http.NotFound(w, r)
case int:
w.WriteHeader(v)
json.NewEncoder(w).Encode(api.ErrorResponse{Error: "stats not available", Code: v, Details: "no stats provider configured"})
_ = json.NewEncoder(w).Encode(api.ErrorResponse{Error: "stats not available", Code: v, Details: "no stats provider configured"})
case string:
w.Write([]byte(v))
_, _ = w.Write([]byte(v))
default:
json.NewEncoder(w).Encode(v)
_ = json.NewEncoder(w).Encode(v)
}
}))
t.Cleanup(srv.Close)
Expand All @@ -81,7 +86,9 @@ func startFakeAPI(t *testing.T, routes map[string]any) *fakeAPI {

func resetFlags(c *cobra.Command) {
reset := func(fl *pflag.Flag) {
fl.Value.Set(fl.DefValue)
if err := fl.Value.Set(fl.DefValue); err != nil {
panic(fmt.Sprintf("reset flag %s to %q: %v", fl.Name, fl.DefValue, err))
}
fl.Changed = false
}
c.Flags().VisitAll(reset)
Expand Down Expand Up @@ -228,7 +235,7 @@ func writeConfig(t *testing.T, content string) {
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Remove(path) })
t.Cleanup(func() { _ = os.Remove(path) })
}

func TestSettingsPrecedence(t *testing.T) {
Expand Down Expand Up @@ -273,7 +280,7 @@ func TestBadSettingsAreRefused(t *testing.T) {
t.Errorf("%s=%q %v: err=%v stderr=%q", tc.env, tc.value, tc.args, err, stderr)
}
if tc.env != "" {
os.Unsetenv(tc.env)
_ = os.Unsetenv(tc.env)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gfsctl/commands/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func serveHealth(t *testing.T, code int, status api.HealthStatus) *fakeAPI {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/api/v1/status" && r.Header.Get("Authorization") == "" {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(api.ErrorResponse{Error: "unauthorized", Code: http.StatusUnauthorized})
_ = json.NewEncoder(w).Encode(api.ErrorResponse{Error: "unauthorized", Code: http.StatusUnauthorized})
return
}
w.WriteHeader(code)
json.NewEncoder(w).Encode(api.HealthResponse{Status: status, Checks: map[string]api.ComponentHealth{
_ = json.NewEncoder(w).Encode(api.HealthResponse{Status: status, Checks: map[string]api.ComponentHealth{
"recovery": {Status: status, Message: "replaying the journal of the crashed node in slot 3"},
}})
}))
Expand Down
Loading