From 7f8ca8046edccf412d95d1536e9e6f02aed80294 Mon Sep 17 00:00:00 2001 From: benvin Date: Sat, 25 Jul 2026 10:00:07 +1000 Subject: [PATCH] Check error returns to satisfy errcheck lint --- main.go | 6 +++--- main_test.go | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 4a4ee3f..c053f17 100644 --- a/main.go +++ b/main.go @@ -55,8 +55,8 @@ func main() { // non-nil error on any failure. func run(args []string, out io.Writer) error { if len(args) == 2 && (args[1] == "-v" || args[1] == "--version") { - fmt.Fprintf(out, "encapic %s\n", version) - return nil + _, err := fmt.Fprintf(out, "encapic %s\n", version) + return err } if len(args) != 2 { return fmt.Errorf("usage: %s ", args[0]) @@ -95,7 +95,7 @@ func fetch(baseURL, certname string) ([]byte, error) { if err != nil { return nil, fmt.Errorf("request %s: %w", url, err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, err := io.ReadAll(resp.Body) if err != nil { diff --git a/main_test.go b/main_test.go index fae7437..90adc0f 100644 --- a/main_test.go +++ b/main_test.go @@ -92,7 +92,7 @@ func TestFetchTimeout(t *testing.T) { client := &http.Client{Timeout: 20 * time.Millisecond} resp, err := client.Get(srv.URL + "/cblr/svc/op/puppet/hostname/host.example") if err == nil { - resp.Body.Close() + _ = resp.Body.Close() t.Fatalf("expected timeout error, got none") } } @@ -119,7 +119,9 @@ func TestRunVersion(t *testing.T) { func TestDefaultBaseURLCompiledIn(t *testing.T) { // Guard against accidental changes to the in-cluster default. - os.Unsetenv("ENCAPI_URL") + if err := os.Unsetenv("ENCAPI_URL"); err != nil { + t.Fatalf("unsetenv: %v", err) + } if defaultBaseURL != "http://encapi.encapi.svc.cluster.local" { t.Errorf("defaultBaseURL = %q", defaultBaseURL) }