From e2709c6511154eff11849bb54c5c925333773732 Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Wed, 9 Apr 2025 15:24:15 +0300 Subject: [PATCH] bump golang to 1.23, golangci-lint to v2, fix errors Signed-off-by: Avi Deitcher --- .github/workflows/ci.yml | 19 ++++++++++--------- Makefile | 4 ++-- cmd/compare.go | 13 ++++++------- cmd/info.go | 6 +++--- cmd/list.go | 6 +++--- cmd/run.go | 6 +++--- local/labels.go | 2 +- local/parser.go | 4 ++-- local/parser_test.go | 2 +- local/script.go | 2 +- local/test.go | 6 +++--- logger/logger_test.go | 2 +- sysinfo/sysinfo_linux.go | 2 +- 13 files changed, 37 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83e0dbd..6c0b660 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.19 - uses: actions/setup-go@v3 + - name: Set up Go 1.23 + uses: actions/setup-go@v5 with: - go-version: 1.19.2 + go-version: 1.23.4 id: go - name: Set path @@ -44,14 +44,14 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.19 - uses: actions/setup-go@v3 + - name: Set up Go 1.23 + uses: actions/setup-go@v5 with: - go-version: 1.19.2 + go-version: 1.23.4 id: go - name: Check out code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: build id: build @@ -69,8 +69,9 @@ jobs: GOPATH: ${{runner.workspace}} - name: Upload binary - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: rtf-binaries + name: ${{steps.build.outputs.binary}} path: ${{steps.build.outputs.binary}} + overwrite: true diff --git a/Makefile b/Makefile index 214aac5..e0a4513 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ ifndef INEFFASSIGN endif @echo "+ $@: golangci-lint, gofmt, go vet, ineffassign" # golangci-lint - @test -z "$$(golangci-lint run ./... | tee /dev/stderr)" + golangci-lint run ./... # gofmt @test -z "$$(gofmt -s -l .| grep -v .pb. | grep -v vendor/ | tee /dev/stderr)" ifeq ($(GOOS),) @@ -62,7 +62,7 @@ endif .PHONY: install-deps install-deps: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2 go install github.com/gordonklaus/ineffassign@latest .PHONY: test diff --git a/cmd/compare.go b/cmd/compare.go index 6e50e22..52fbace 100644 --- a/cmd/compare.go +++ b/cmd/compare.go @@ -18,7 +18,6 @@ import ( "encoding/csv" "encoding/json" "fmt" - "io/ioutil" "os" "strings" "text/tabwriter" @@ -55,13 +54,13 @@ func compare(_ *cobra.Command, args []string) error { var summaries []local.Summary for _, fileName := range args { - data, err := ioutil.ReadFile(fileName) + data, err := os.ReadFile(fileName) if err != nil { return err } var s local.Summary if err := json.Unmarshal(data, &s); err != nil { - return fmt.Errorf("Failed to unmarshal %s: %v", fileName, err) + return fmt.Errorf("failed to unmarshal %s: %v", fileName, err) } summaries = append(summaries, s) } @@ -74,7 +73,7 @@ func compare(_ *cobra.Command, args []string) error { heading := []string{"Name"} if !csvCompare { heading = append(heading, args...) - fmt.Fprintln(tw, strings.Join(heading, "\t")) + _, _ = fmt.Fprintln(tw, strings.Join(heading, "\t")) } else { ids := []string{"ID"} starts := []string{"Start Time"} @@ -101,7 +100,7 @@ func compare(_ *cobra.Command, args []string) error { for j := range summaries { r := summaries[j].Results[i] if r.Name != name { - return fmt.Errorf("List of results for %s don't match %s: %s != %s", args[0], args[j], r.Name, name) + return fmt.Errorf("list of results for %s don't match %s: %s != %s", args[0], args[j], r.Name, name) } resStr := r.TestResult.Sprintf("%s (%s)", @@ -112,14 +111,14 @@ func compare(_ *cobra.Command, args []string) error { results = append(results, resStr) } if !csvCompare { - fmt.Fprintln(tw, strings.Join(results, "\t")) + _, _ = fmt.Fprintln(tw, strings.Join(results, "\t")) } else { if err := cw.Write(results); err != nil { return err } } } - tw.Flush() + _ = tw.Flush() cw.Flush() return nil } diff --git a/cmd/info.go b/cmd/info.go index 35d0dce..33b5035 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -54,7 +54,7 @@ func info(_ *cobra.Command, _ []string) error { lst := p.List(config) if !csvInfo { - fmt.Fprintf(tw, "NAME\tDESCRIPTION\n") + _, _ = fmt.Fprintf(tw, "NAME\tDESCRIPTION\n") } else { heading := []string{"Name", "Description", "Known issues"} if err := cw.Write(heading); err != nil { @@ -64,7 +64,7 @@ func info(_ *cobra.Command, _ []string) error { for _, i := range lst { if !csvInfo { - fmt.Fprintf(tw, "%s\t%s\n", i.Name, i.Summary) + _, _ = fmt.Fprintf(tw, "%s\t%s\n", i.Name, i.Summary) } else { out := []string{i.Name, i.Summary, i.Issue} if err := cw.Write(out); err != nil { @@ -72,7 +72,7 @@ func info(_ *cobra.Command, _ []string) error { } } } - tw.Flush() + _ = tw.Flush() cw.Flush() return nil } diff --git a/cmd/list.go b/cmd/list.go index baf4d53..5fb75c4 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -63,11 +63,11 @@ func list(_ *cobra.Command, args []string) error { w.Init(os.Stdout, 0, 8, 0, '\t', 0) lst := p.List(config) - fmt.Fprint(w, "STATE\tTEST\tLABELS\n") + _, _ = fmt.Fprint(w, "STATE\tTEST\tLABELS\n") for _, i := range lst { state := i.TestResult.Sprintf(local.TestResultNames[i.TestResult]) - fmt.Fprintf(w, "%s\t%s\t%s\n", state, i.Name, i.LabelString()) + _, _ = fmt.Fprintf(w, "%s\t%s\t%s\n", state, i.Name, i.LabelString()) } - w.Flush() + _ = w.Flush() return nil } diff --git a/cmd/run.go b/cmd/run.go index 7aa904a..31d580b 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -148,7 +148,7 @@ func run(cmd *cobra.Command, args []string) error { if err != nil { return err } - defer tf.Close() + defer func() { _ = tf.Close() }() tCsv := csv.NewWriter(tf) if err = tCsv.Write(testCsvFields); err != nil { @@ -159,7 +159,7 @@ func run(cmd *cobra.Command, args []string) error { if err != nil { return err } - defer sf.Close() + defer func() { _ = sf.Close() }() sCsv := csv.NewWriter(sf) @@ -288,7 +288,7 @@ func run(cmd *cobra.Command, args []string) error { log.Log(logger.LevelSummary, fmt.Sprintf("Duration: %.2fs", duration.Seconds())) if failed > 0 { - return fmt.Errorf("Some tests failed") + return fmt.Errorf("some tests failed") } return nil } diff --git a/local/labels.go b/local/labels.go index f5a7b42..1f861a5 100644 --- a/local/labels.go +++ b/local/labels.go @@ -103,7 +103,7 @@ func NewRunConfig(labels string, pattern string) RunConfig { // ValidatePattern validates that an arg string is a valid test pattern func ValidatePattern(args []string) (string, error) { if len(args) > 1 { - return "", fmt.Errorf("Expected only one test pattern") + return "", fmt.Errorf("expected only one test pattern") } if len(args) == 0 { return "", nil diff --git a/local/parser.go b/local/parser.go index 47f08da..71c0c4c 100644 --- a/local/parser.go +++ b/local/parser.go @@ -43,7 +43,7 @@ func ParseTags(file string) (*Tags, error) { if err != nil { return nil, err } - defer f.Close() + defer func() { _ = f.Close() }() tags := &Tags{} scanner := bufio.NewScanner(f) @@ -80,7 +80,7 @@ func ParseTags(file string) (*Tags, error) { } } else { if v.String() != "" { - return nil, fmt.Errorf("Field %s specified multiple times", rt) + return nil, fmt.Errorf("field %s specified multiple times", rt) } v.SetString(tagValue) } diff --git a/local/parser_test.go b/local/parser_test.go index 0bc239e..a325617 100644 --- a/local/parser_test.go +++ b/local/parser_test.go @@ -36,7 +36,7 @@ func TestParseBadTags(t *testing.T) { if err == nil { t.Fatalf("Should have caused an error") } - if err.Error() != "Field LABELS specified multiple times" { + if err.Error() != "field LABELS specified multiple times" { t.Fatalf("Wrong error message") } } diff --git a/local/script.go b/local/script.go index 28a43ca..78edc42 100644 --- a/local/script.go +++ b/local/script.go @@ -61,7 +61,7 @@ func executeScript(script, cwd, name string, args []string, config RunConfig) (R } } if executable == "" { - return Result{}, fmt.Errorf("Can't find a suitable shell to execute %s", script) + return Result{}, fmt.Errorf("can't find a suitable shell to execute %s", script) } cmdArgs = append(cmdArgs, script) cmdArgs = append(cmdArgs, args...) diff --git a/local/test.go b/local/test.go index 4d9bdc4..8c9d419 100644 --- a/local/test.go +++ b/local/test.go @@ -37,7 +37,7 @@ func (t *Test) Init() error { t.Summary = tags.Summary order, name := getNameAndOrder(filepath.Base(t.Path)) if t.Parent == nil { - return fmt.Errorf("A test should have a parent group") + return fmt.Errorf("a test should have a parent group") } t.Tags.Name = fmt.Sprintf("%s.%s", t.Parent.Name(), name) t.Labels, t.NotLabels = ParseLabels(t.Tags.Labels) @@ -129,7 +129,7 @@ func (t *Test) Run(config RunConfig) ([]Result, error) { if t.Parent.PreTestPath != "" { res, err := executeScript(t.Parent.PreTestPath, t.Path, name, []string{name}, config) if res.TestResult != Pass { - return results, fmt.Errorf("Error running: %s. %s", t.Parent.PreTestPath, err.Error()) + return results, fmt.Errorf("error running: %s. %s", t.Parent.PreTestPath, err.Error()) } } // Run the test @@ -156,7 +156,7 @@ func (t *Test) Run(config RunConfig) ([]Result, error) { if t.Parent.PostTestPath != "" { res, err := executeScript(t.Parent.PostTestPath, t.Path, name, []string{name, fmt.Sprintf("%d", res.TestResult)}, config) if res.TestResult != Pass { - return results, fmt.Errorf("Error running: %s. %s", t.Parent.PostTestPath, err.Error()) + return results, fmt.Errorf("error running: %s. %s", t.Parent.PostTestPath, err.Error()) } } res.Test = t diff --git a/logger/logger_test.go b/logger/logger_test.go index 9023e26..734fe9d 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -11,7 +11,7 @@ func TestFileLogger(t *testing.T) { if err != nil { t.Fatal(err) } - defer f.Close() + defer func() { _ = f.Close() }() l := NewFileLogger(f) l.SetLevel(LevelDebug) diff --git a/sysinfo/sysinfo_linux.go b/sysinfo/sysinfo_linux.go index e796a72..c5f4f07 100644 --- a/sysinfo/sysinfo_linux.go +++ b/sysinfo/sysinfo_linux.go @@ -42,7 +42,7 @@ func getPlatformSpecifics(info SystemInfo) SystemInfo { v := strings.TrimSpace(fs[1]) if k == "MemTotal" { - v = strings.Replace(v, " kB", "", -1) + v = strings.ReplaceAll(v, " kB", "") n, _ := strconv.ParseInt(v, 10, 64) info.Memory = n * 1024 break