Update to Go 1.23 (#14818)

* Update to Go 1.23

* Update bazel version

* Update rules_go

* Use toolchains_protoc

* Update go_honnef_go_tools

* Update golang.org/x/tools

* Fix violations of SA3000

* Update errcheck by re-exporting the upstream repo

* Remove problematic ginkgo and gomega test helpers. Rewrote tests without these test libraries.

* Update go to 1.23.5

* gofmt with go1.23.5

* Revert Patch

* Unclog

* Update for go 1.23 support

* Fix Lint Issues

* Gazelle

* Fix Build

* Fix Lint

* no lint

* Fix lint

* Fix lint

* Disable intrange

* Preston's review

---------

Co-authored-by: Preston Van Loon <preston@pvl.dev>
This commit is contained in:
Nishant Das
2025-01-24 12:53:23 +08:00
committed by GitHub
parent 2c78e501b3
commit 5d6a406829
47 changed files with 306 additions and 2354 deletions

View File

@@ -14,15 +14,10 @@ go_library(
go_test(
name = "go_default_test",
srcs = [
"formatter_test.go",
"logrus_prefixed_formatter_suite_test.go",
],
srcs = ["formatter_test.go"],
deps = [
":go_default_library",
"//testing/require:go_default_library",
"@com_github_onsi_ginkgo//:go_default_library",
"@com_github_onsi_gomega//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],

View File

@@ -5,55 +5,76 @@ import (
"regexp"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
prefixed "github.com/prysmaticlabs/prysm/v5/runtime/logging/logrus-prefixed-formatter"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/sirupsen/logrus"
)
var _ = Describe("Formatter", func() {
var formatter *prefixed.TextFormatter
var log *logrus.Logger
var output *LogOutput
type LogOutput struct {
buffer string
}
BeforeEach(func() {
output = new(LogOutput)
formatter = new(prefixed.TextFormatter)
log = logrus.New()
log.Out = output
log.Formatter = formatter
log.Level = logrus.DebugLevel
})
func (o *LogOutput) Write(p []byte) (int, error) {
o.buffer += string(p)
return len(p), nil
}
Describe("logfmt output", func() {
It("should output simple message", func() {
func (o *LogOutput) GetValue() string {
return o.buffer
}
func TestFormatter_logfmt_output(t *testing.T) {
tests := []struct {
name string
callback func(l *logrus.Logger)
expected string
}{
{
name: "should output simple message",
callback: func(l *logrus.Logger) {
l.Debug("test")
},
expected: "level=debug msg=test\n",
},
{
name: "should output message with additional field",
callback: func(l *logrus.Logger) {
l.WithFields(logrus.Fields{"animal": "walrus"}).Debug("test")
},
expected: "level=debug msg=test animal=walrus\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output := new(LogOutput)
formatter := new(prefixed.TextFormatter)
formatter.DisableTimestamp = true
log.Debug("test")
Ω(output.GetValue()).Should(Equal("level=debug msg=test\n"))
log := logrus.New()
log.Out = output
log.Formatter = formatter
log.Level = logrus.DebugLevel
tt.callback(log)
require.Equal(t, output.GetValue(), tt.expected)
})
}
}
It("should output message with additional field", func() {
formatter.DisableTimestamp = true
log.WithFields(logrus.Fields{"animal": "walrus"}).Debug("test")
Ω(output.GetValue()).Should(Equal("level=debug msg=test animal=walrus\n"))
})
})
func TestFormatter_formatted_output(t *testing.T) {
output := new(LogOutput)
formatter := new(prefixed.TextFormatter)
formatter.DisableTimestamp = true
formatter.ForceFormatting = true
log := logrus.New()
log.Out = output
log.Formatter = formatter
log.Level = logrus.DebugLevel
Describe("Formatted output", func() {
It("should output formatted message", func() {
formatter.DisableTimestamp = true
formatter.ForceFormatting = true
log.Debug("test")
Ω(output.GetValue()).Should(Equal("DEBUG test\n"))
})
})
Describe("Theming support", func() {
})
})
log.Debug("test")
require.Equal(t, output.GetValue(), "DEBUG test\n")
}
func TestFormatter_SuppressErrorStackTraces(t *testing.T) {
formatter := new(prefixed.TextFormatter)

View File

@@ -1,26 +0,0 @@
package prefixed_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type LogOutput struct {
buffer string
}
func (o *LogOutput) Write(p []byte) (int, error) {
o.buffer += string(p)
return len(p), nil
}
func (o *LogOutput) GetValue() string {
return o.buffer
}
func TestLogrusPrefixedFormatter(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "LogrusPrefixedFormatter Suite")
}