chore: upgrade Go to 1.27 (#30601)

This commit is contained in:
andig 2026-08-20 13:36:53 +02:00 • committed by GitHub
parent 748d36d130
commit e63bae0c8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 135 additions and 154 deletions

View file

@ -46,7 +46,7 @@ func NewCachedFromConfig(ctx context.Context, other map[string]any) (Plugin, err
}, nil
}
func cachedGetter[T any](o *cachedPlugin, valuer func(ctx context.Context) (func() (T, error), error)) (func() (T, error), error) {
func (o *cachedPlugin) cachedGetter[T any](valuer func(ctx context.Context) (func() (T, error), error)) (func() (T, error), error) {
value, err := valuer(o.ctx)
if err != nil {
return nil, fmt.Errorf("cached: %w", err)
@ -77,23 +77,23 @@ func cachedGetter[T any](o *cachedPlugin, valuer func(ctx context.Context) (func
var _ StringGetter = (*cachedPlugin)(nil)
func (o *cachedPlugin) StringGetter() (func() (string, error), error) {
return cachedGetter(o, o.value.StringGetter)
return o.cachedGetter(o.value.StringGetter)
}
var _ FloatGetter = (*cachedPlugin)(nil)
func (o *cachedPlugin) FloatGetter() (func() (float64, error), error) {
return cachedGetter(o, o.value.FloatGetter)
return o.cachedGetter(o.value.FloatGetter)
}
var _ IntGetter = (*cachedPlugin)(nil)
func (o *cachedPlugin) IntGetter() (func() (int64, error), error) {
return cachedGetter(o, o.value.IntGetter)
return o.cachedGetter(o.value.IntGetter)
}
var _ BoolGetter = (*cachedPlugin)(nil)
func (o *cachedPlugin) BoolGetter() (func() (bool, error), error) {
return cachedGetter(o, o.value.BoolGetter)
return o.cachedGetter(o.value.BoolGetter)
}

View file

@ -15,7 +15,7 @@ func TestCachedHitAndExpiry(t *testing.T) {
o := &cachedPlugin{ctx: context.Background(), clock: c, cache: time.Hour}
var calls int
get, err := cachedGetter(o, func(context.Context) (func() (int64, error), error) {
get, err := o.cachedGetter(func(context.Context) (func() (int64, error), error) {
return func() (int64, error) {
calls++
return int64(calls), nil
@ -47,7 +47,7 @@ func TestCachedDoesNotCacheErrors(t *testing.T) {
o := &cachedPlugin{ctx: context.Background(), clock: c, cache: time.Hour}
var calls int
get, err := cachedGetter(o, func(context.Context) (func() (int64, error), error) {
get, err := o.cachedGetter(func(context.Context) (func() (int64, error), error) {
return func() (int64, error) {
calls++
return 0, errors.New("boom")

View file

@ -60,11 +60,8 @@ type httpTestSuite struct {
func (suite *httpTestSuite) SetupSuite() {
suite.h = new(httpHandler)
suite.srv = httptest.NewServer(suite.h)
}
func (suite *httpTestSuite) TearDown() {
suite.srv.Close()
suite.srv = httptest.NewTestServer(suite.T(), suite.h)
suite.srv.Start()
}
func (suite *httpTestSuite) TestGet() {

View file

@ -125,7 +125,7 @@ func (p *Script) StringGetter() (func() (string, error), error) {
}, nil
}
func scriptSetter[T any](p *Script, param string) (func(T) error, error) {
func (p *Script) scriptSetter[T any](param string) (func(T) error, error) {
return func(val T) error {
cmd, err := util.ReplaceFormatted(p.script, map[string]any{
param: val,
@ -143,19 +143,19 @@ var _ IntSetter = (*Script)(nil)
// IntSetter invokes script with parameter replaced by int value
func (p *Script) IntSetter(param string) (func(int64) error, error) {
return scriptSetter[int64](p, param)
return p.scriptSetter[int64](param)
}
var _ BoolSetter = (*Script)(nil)
// BoolSetter invokes script with parameter replaced by bool value
func (p *Script) BoolSetter(param string) (func(bool) error, error) {
return scriptSetter[bool](p, param)
return p.scriptSetter[bool](param)
}
var _ StringSetter = (*Script)(nil)
// StringSetter returns a function that invokes a script with parameter by a string value
func (p *Script) StringSetter(param string) (func(string) error, error) {
return scriptSetter[string](p, param)
return p.scriptSetter[string](param)
}

View file

@ -33,8 +33,7 @@ func NewSleepFromConfig(ctx context.Context, other map[string]any) (Plugin, erro
}
// sleeper is the generic sleeper function for sleepPlugin
// it is currently not possible to write this as a method
func sleeper[T comparable](o *sleepPlugin) func(T) error {
func (o *sleepPlugin) sleeper[T comparable]() func(T) error {
return func(val T) error {
<-time.After(o.duration)
@ -45,17 +44,17 @@ func sleeper[T comparable](o *sleepPlugin) func(T) error {
var _ IntSetter = (*sleepPlugin)(nil)
func (o *sleepPlugin) IntSetter(param string) (func(int64) error, error) {
return sleeper[int64](o), nil
return o.sleeper[int64](), nil
}
var _ FloatSetter = (*sleepPlugin)(nil)
func (o *sleepPlugin) FloatSetter(param string) (func(float64) error, error) {
return sleeper[float64](o), nil
return o.sleeper[float64](), nil
}
var _ BoolSetter = (*sleepPlugin)(nil)
func (o *sleepPlugin) BoolSetter(param string) (func(bool) error, error) {
return sleeper[bool](o), nil
return o.sleeper[bool](), nil
}

View file

@ -16,7 +16,7 @@ func TestSockePlugin(t *testing.T) {
ctx, cancel := context.WithTimeout(t.Context(), time.Second*10)
defer cancel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srv := httptest.NewTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c, err := websocket.Accept(w, r, nil)
require.NoError(t, err)
defer c.Close(websocket.StatusNormalClosure, "")
@ -36,8 +36,7 @@ func TestSockePlugin(t *testing.T) {
}
}
}))
defer srv.Close()
srv.Start()
addr := "ws://" + srv.Listener.Addr().String()
p, err := NewSocketPluginFromConfig(map[string]any{

View file

@ -48,9 +48,7 @@ func NewValidPlugin(ctx context.Context, valid func() (bool, error), value Confi
}
}
var _ StringGetter = (*validPlugin)(nil)
func validGetter[T any](o *validPlugin, valuer func(ctx context.Context) (func() (T, error), error)) (func() (T, error), error) {
func (o *validPlugin) validGetter[T any](valuer func(ctx context.Context) (func() (T, error), error)) (func() (T, error), error) {
value, err := valuer(o.ctx)
if err != nil {
return nil, fmt.Errorf("valid: %w", err)
@ -74,17 +72,17 @@ func validGetter[T any](o *validPlugin, valuer func(ctx context.Context) (func()
var _ StringGetter = (*validPlugin)(nil)
func (o *validPlugin) StringGetter() (func() (string, error), error) {
return validGetter(o, o.value.StringGetter)
return o.validGetter(o.value.StringGetter)
}
var _ FloatGetter = (*validPlugin)(nil)
func (o *validPlugin) FloatGetter() (func() (float64, error), error) {
return validGetter(o, o.value.FloatGetter)
return o.validGetter(o.value.FloatGetter)
}
var _ IntGetter = (*validPlugin)(nil)
func (o *validPlugin) IntGetter() (func() (int64, error), error) {
return validGetter(o, o.value.IntGetter)
return o.validGetter(o.value.IntGetter)
}

View file

@ -76,8 +76,7 @@ type deferredState[T comparable] struct {
}
// setter is the generic setter function for watchdogPlugin
// it is currently not possible to write this as a method
func setter[T comparable](o *watchdogPlugin, set func(T) error, reset []T) func(T) error {
func (o *watchdogPlugin) setter[T comparable](set func(T) error, reset []T) func(T) error {
var state *deferredState[T]
// seed with now, not zero: otherwise the first write's delay computes to 0 and skips
// deferral, which is wrong for an unknown last write
@ -195,7 +194,7 @@ func (o *watchdogPlugin) IntSetter(param string) (func(int64) error, error) {
}
}
res := setter(o, set, reset)
res := o.setter(set, reset)
if o.initial != nil {
val, err := strconv.ParseInt(*o.initial, 10, 64)
if err != nil {
@ -229,7 +228,7 @@ func (o *watchdogPlugin) FloatSetter(param string) (func(float64) error, error)
}
}
res := setter(o, set, reset)
res := o.setter(set, reset)
if o.initial != nil {
val, err := strconv.ParseFloat(*o.initial, 64)
if err != nil {
@ -263,7 +262,7 @@ func (o *watchdogPlugin) BoolSetter(param string) (func(bool) error, error) {
reset = append(reset, val)
}
res := setter(o, set, reset)
res := o.setter(set, reset)
if o.initial != nil {
val, err := strconv.ParseBool(*o.initial)
if err != nil {

View file

@ -22,7 +22,7 @@ func TestWatchdogSetterConcurrency(t *testing.T) {
var u atomic.Uint32
set := setter(p, func(i int) error {
set := p.setter(func(i int) error {
if !u.CompareAndSwap(0, 1) {
return errors.New("race")
}
@ -63,7 +63,7 @@ func TestWatchdogDeferredUpdate(t *testing.T) {
}
var calls []int
set := setter(p, func(i int) error {
set := p.setter(func(i int) error {
calls = append(calls, i)
return nil
}, []int{1}) // 1 is reset value
@ -108,7 +108,7 @@ func TestWatchdogCancelPendingDeferredUpdate(t *testing.T) {
}
var calls []int
set := setter(p, func(i int) error {
set := p.setter(func(i int) error {
calls = append(calls, i)
return nil
}, []int{1}) // 1 is reset value
@ -154,7 +154,7 @@ func TestWatchdogDelayBackwardCompatibility(t *testing.T) {
}
var calls []int
set := setter(p, func(i int) error {
set := p.setter(func(i int) error {
calls = append(calls, i)
return nil
}, []int{1}) // 1 is reset value
@ -185,7 +185,7 @@ func TestWatchdogResetStopsInflightTick(t *testing.T) {
var sawReset, stale atomic.Bool
set := setter(p, func(v int) error {
set := p.setter(func(v int) error {
if v == 1 {
sawReset.Store(true)
// hold the lock so an in-flight tick queues behind the reset