Skip to content

Commit f77322b

Browse files
authored
build: bump Go version requirement to 1.24 (#7839)
Go 1.23 is no longer supported as per Go release policy. Changes: - Use Go v1.24.6 as the project SDK requirement - Apply lint fixes for Go 1.24 - Fix "non-constant format string in call" issues as seen in CI. Signed-off-by: Ville Vesilehto <[email protected]>
1 parent e04cf20 commit f77322b

File tree

100 files changed

+879
-940
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+879
-940
lines changed

bundle/store_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package bundle
66

77
import (
8-
"context"
98
"fmt"
109
"strings"
1110
"testing"
@@ -17,7 +16,7 @@ import (
1716
)
1817

1918
func TestHasRootsOverlap(t *testing.T) {
20-
ctx := context.Background()
19+
ctx := t.Context()
2120

2221
cases := []struct {
2322
note string
@@ -181,7 +180,7 @@ func TestActivate_DefaultRegoVersion(t *testing.T) {
181180

182181
for _, tc := range tests {
183182
t.Run(tc.note, func(t *testing.T) {
184-
ctx := context.Background()
183+
ctx := t.Context()
185184
store := mock.New()
186185
txn := storage.NewTransactionOrDie(ctx, store, storage.WriteParams)
187186
compiler := ast.NewCompiler().WithDefaultRegoVersion(ast.RegoV0CompatV1)
@@ -329,7 +328,7 @@ func TestDeactivate_DefaultRegoVersion(t *testing.T) {
329328

330329
for _, tc := range tests {
331330
t.Run(tc.note, func(t *testing.T) {
332-
ctx := context.Background()
331+
ctx := t.Context()
333332
store := mock.New()
334333
txn := storage.NewTransactionOrDie(ctx, store, storage.WriteParams)
335334

cmd/eval_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package cmd
88
import (
99
"bufio"
1010
"bytes"
11-
"context"
1211
"errors"
1312
"fmt"
1413
"maps"
@@ -1793,7 +1792,7 @@ func TestResetExprLocations(t *testing.T) {
17931792
17941793
q contains 1
17951794
q contains 2
1796-
`)).Partial(context.Background())
1795+
`)).Partial(t.Context())
17971796

17981797
if err != nil {
17991798
t.Fatal(err)

cmd/exec_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ main contains "hello" if {
301301
testLogger := loggingtest.New()
302302
params.Logger = testLogger
303303

304-
ctx, cancel := context.WithCancel(context.Background())
304+
ctx, cancel := context.WithCancel(t.Context())
305305
defer cancel()
306306
go func(expectedErrors []string) {
307307
err := runExecWithContext(ctx, params)
@@ -531,7 +531,7 @@ main contains "hello" if {
531531
testLogger := loggingtest.New()
532532
params.Logger = testLogger
533533

534-
ctx, cancel := context.WithCancel(context.Background())
534+
ctx, cancel := context.WithCancel(t.Context())
535535
defer cancel()
536536
go func(expectedErrors []string) {
537537
err := runExecWithContext(ctx, params)
@@ -891,7 +891,7 @@ main contains "hello" if {
891891
testLogger := loggingtest.New()
892892
params.Logger = testLogger
893893

894-
ctx, cancel := context.WithCancel(context.Background())
894+
ctx, cancel := context.WithCancel(t.Context())
895895
defer cancel()
896896
go func() {
897897
err := runExecWithContext(ctx, params)
@@ -950,7 +950,7 @@ func TestInvalidConfig(t *testing.T) {
950950
params.Fail = true
951951
params.FailDefined = true
952952

953-
err := exec.Exec(context.TODO(), nil, params)
953+
err := exec.Exec(t.Context(), nil, params)
954954
if err == nil || err.Error() != "specify --fail or --fail-defined but not both" {
955955
t.Fatalf("Expected error '%s' but got '%s'", "specify --fail or --fail-defined but not both", err.Error())
956956
}
@@ -963,7 +963,7 @@ func TestInvalidConfigAllThree(t *testing.T) {
963963
params.FailDefined = true
964964
params.FailNonEmpty = true
965965

966-
err := exec.Exec(context.TODO(), nil, params)
966+
err := exec.Exec(t.Context(), nil, params)
967967
if err == nil || err.Error() != "specify --fail or --fail-defined but not both" {
968968
t.Fatalf("Expected error '%s' but got '%s'", "specify --fail or --fail-defined but not both", err.Error())
969969
}
@@ -975,7 +975,7 @@ func TestInvalidConfigNonEmptyAndFail(t *testing.T) {
975975
params.FailNonEmpty = true
976976
params.Fail = true
977977

978-
err := exec.Exec(context.TODO(), nil, params)
978+
err := exec.Exec(t.Context(), nil, params)
979979
if err == nil || err.Error() != "specify --fail-non-empty or --fail but not both" {
980980
t.Fatalf("Expected error '%s' but got '%s'", "specify --fail-non-empty or --fail but not both", err.Error())
981981
}
@@ -987,7 +987,7 @@ func TestInvalidConfigNonEmptyAndFailDefined(t *testing.T) {
987987
params.FailNonEmpty = true
988988
params.FailDefined = true
989989

990-
err := exec.Exec(context.TODO(), nil, params)
990+
err := exec.Exec(t.Context(), nil, params)
991991
if err == nil || err.Error() != "specify --fail-non-empty or --fail-defined but not both" {
992992
t.Fatalf("Expected error '%s' but got '%s'", "specify --fail-non-empty or --fail-defined but not both", err.Error())
993993
}

cmd/internal/exec/exec_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package exec
22

33
import (
44
"bytes"
5-
"context"
65
"os"
76
"path/filepath"
87
"strings"
@@ -227,7 +226,7 @@ func TestExec(t *testing.T) {
227226
params.Paths = append(params.Paths, dir+"/files/")
228227
}
229228

230-
ctx := context.Background()
229+
ctx := t.Context()
231230
opa, _ := sdk.New(ctx, sdk.Options{
232231
Config: bytes.NewReader([]byte{}),
233232
Logger: logging.NewNoOpLogger(),

cmd/internal/exec/json_reporter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestJsonReporter_Close(t *testing.T) {
3434

3535
func TestJsonReporter_StoreDecision(t *testing.T) {
3636
testString := "test"
37-
ctx := context.TODO()
37+
ctx := t.Context()
3838
tcs := []struct {
3939
Name string
4040
Path string
@@ -142,7 +142,7 @@ func TestJsonReporter_ReportFailure(t *testing.T) {
142142
for _, tc := range tcs {
143143
t.Run(tc.Name, func(t *testing.T) {
144144
wr := bytes.NewBuffer([]byte{})
145-
ctx := context.Background()
145+
ctx := t.Context()
146146
j := jsonReporter{
147147
w: wr,
148148
buf: []result{},

cmd/run_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
func TestRunServerBase(t *testing.T) {
2626
params := newTestRunParams()
27-
ctx, cancel := context.WithCancel(context.Background())
27+
ctx, cancel := context.WithCancel(t.Context())
2828

2929
rt, err := initRuntime(ctx, params, nil, false)
3030
if err != nil {
@@ -57,7 +57,7 @@ func TestRunServerBaseListenOnLocalhost(t *testing.T) {
5757
params := newTestRunParams()
5858
params.rt.V1Compatible = true
5959

60-
ctx, cancel := context.WithCancel(context.Background())
60+
ctx, cancel := context.WithCancel(t.Context())
6161

6262
rt, err := initRuntime(ctx, params, nil, true)
6363
if err != nil {
@@ -98,7 +98,7 @@ func TestRunServerBaseListenOnLocalhost(t *testing.T) {
9898
func TestRunServerWithDiagnosticAddr(t *testing.T) {
9999
params := newTestRunParams()
100100
params.rt.DiagnosticAddrs = &[]string{"localhost:0"}
101-
ctx, cancel := context.WithCancel(context.Background())
101+
ctx, cancel := context.WithCancel(t.Context())
102102

103103
rt, err := initRuntime(ctx, params, nil, false)
104104
if err != nil {
@@ -141,7 +141,7 @@ func TestInitRuntimeVerifyNonBundle(t *testing.T) {
141141
params.pubKey = "secret"
142142
params.serverMode = false
143143

144-
_, err := initRuntime(context.Background(), params, nil, false)
144+
_, err := initRuntime(t.Context(), params, nil, false)
145145
if err == nil {
146146
t.Fatal("Expected error but got nil")
147147
}
@@ -175,7 +175,7 @@ func TestInitRuntimeCipherSuites(t *testing.T) {
175175
params.cipherSuites = tc.cipherSuites
176176
}
177177

178-
rt, err := initRuntime(context.Background(), params, nil, false)
178+
rt, err := initRuntime(t.Context(), params, nil, false)
179179
fmt.Println(err)
180180

181181
if !tc.expErr && err != nil {
@@ -219,7 +219,7 @@ func TestInitRuntimeSkipKnownSchemaCheck(t *testing.T) {
219219
t.Fatal(err)
220220
}
221221

222-
_, err = initRuntime(context.Background(), params, []string{rootDir}, false)
222+
_, err = initRuntime(t.Context(), params, []string{rootDir}, false)
223223
if err == nil {
224224
t.Fatal("Expected error but got nil")
225225
}
@@ -230,7 +230,7 @@ func TestInitRuntimeSkipKnownSchemaCheck(t *testing.T) {
230230

231231
// skip type checking for known input schemas
232232
params.skipKnownSchemaCheck = true
233-
_, err = initRuntime(context.Background(), params, []string{rootDir}, false)
233+
_, err = initRuntime(t.Context(), params, []string{rootDir}, false)
234234
if err != nil {
235235
t.Fatal(err)
236236
}
@@ -282,7 +282,7 @@ func TestRunServerUploadPolicy(t *testing.T) {
282282

283283
for i, tc := range tests {
284284
t.Run(tc.note, func(t *testing.T) {
285-
ctx, cancel := context.WithCancel(context.Background())
285+
ctx, cancel := context.WithCancel(t.Context())
286286

287287
params := newTestRunParams()
288288
params.rt.V0Compatible = tc.v0Compatible
@@ -345,7 +345,7 @@ func TestRunServerCheckLogTimestampFormat(t *testing.T) {
345345
}
346346

347347
func checkLogTimeStampFormat(t *testing.T, params runCmdParams, format string) {
348-
ctx, cancel := context.WithCancel(context.Background())
348+
ctx, cancel := context.WithCancel(t.Context())
349349

350350
rt, err := initRuntime(ctx, params, nil, false)
351351
if err != nil {
@@ -417,7 +417,7 @@ func TestInitRuntimeAddrSetByUser(t *testing.T) {
417417

418418
params := newTestRunParams()
419419
params.rt.Addrs = &[]string{"localhost:0"}
420-
ctx, cancel := context.WithCancel(context.Background())
420+
ctx, cancel := context.WithCancel(t.Context())
421421

422422
rt, err := initRuntime(ctx, params, []string{}, cmd.Flags().Changed("addr"))
423423
if err != nil {

cmd/test_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func failTrace(t *testing.T) []*topdown.Event {
216216
rego.Trace(true),
217217
rego.QueryTracer(tracer),
218218
rego.Query("data.testing.test_p"),
219-
).Eval(context.Background())
219+
).Eval(t.Context())
220220

221221
if err != nil {
222222
t.Fatalf("Unexpected error: %s", err)
@@ -3655,7 +3655,7 @@ func TestWithDefaultRegoPlugin(t *testing.T) {
36553655
})
36563656

36573657
t.Run("repl", func(t *testing.T) {
3658-
ctx := context.Background()
3658+
ctx := t.Context()
36593659
store := inmem.New()
36603660
var buffer bytes.Buffer
36613661
repl := repl.New(store, "", &buffer, "", 0, "")

compile/compile_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package compile
66

77
import (
8-
"context"
98
"fmt"
109
"io/fs"
1110
"maps"
@@ -77,7 +76,7 @@ func TestCompilerDefaultRegoVersion(t *testing.T) {
7776
WithFS(fsys).
7877
WithPaths(root)
7978

80-
err := compiler.Build(context.Background())
79+
err := compiler.Build(t.Context())
8180

8281
if len(tc.expErrs) > 0 {
8382
if err == nil {
@@ -336,7 +335,7 @@ p contains "B" if {
336335

337336
for _, bundleType := range bundleTypeCases {
338337
for _, tc := range tests {
339-
ctx := context.Background()
338+
ctx := t.Context()
340339
t.Run(fmt.Sprintf("%s, %s", bundleType.note, tc.note), func(t *testing.T) {
341340
files := map[string]string{}
342341
if bundleType.tar {

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/open-policy-agent/opa
22

3-
go 1.23.12
4-
5-
toolchain go1.24.6
3+
go 1.24.6
64

75
require (
86
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2

internal/presentation/presentation_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package presentation
66

77
import (
88
"bytes"
9-
"context"
109
"encoding/json"
1110
"errors"
1211
"fmt"
@@ -126,8 +125,8 @@ func TestOutputJSONErrorStructuredASTErr(t *testing.T) {
126125

127126
func TestOutputJSONErrorStructuredStorageErr(t *testing.T) {
128127
store := inmem.New()
129-
txn := storage.NewTransactionOrDie(context.Background(), store)
130-
err := store.Write(context.Background(), txn, storage.AddOp, storage.Path{}, map[string]any{"foo": 1})
128+
txn := storage.NewTransactionOrDie(t.Context(), store)
129+
err := store.Write(t.Context(), txn, storage.AddOp, storage.Path{}, map[string]any{"foo": 1})
131130
expected := `{
132131
"errors": [
133132
{
@@ -156,7 +155,7 @@ func TestOutputJSONErrorStructuredTopdownErr(t *testing.T) {
156155
_, err := rego.New(
157156
rego.Module("test.rego", mod),
158157
rego.Query("data.test.z"),
159-
).Eval(context.Background())
158+
).Eval(t.Context())
160159

161160
expected := `{
162161
"errors": [
@@ -177,7 +176,7 @@ func TestOutputJSONErrorStructuredTopdownErr(t *testing.T) {
177176
}
178177

179178
func TestOutputJSONErrorStructuredAstErr(t *testing.T) {
180-
_, err := rego.New(rego.Query("count(0)")).Eval(context.Background())
179+
_, err := rego.New(rego.Query("count(0)")).Eval(t.Context())
181180
expected := `{
182181
"errors": [
183182
{
@@ -249,7 +248,7 @@ func TestOutputJSONErrorStructuredAstParseErr(t *testing.T) {
249248
_, err := rego.New(
250249
rego.Module("parse-err.rego", "!!!"),
251250
rego.Query("!!!"),
252-
).Eval(context.Background())
251+
).Eval(t.Context())
253252

254253
expected := `{
255254
"errors": [
@@ -359,7 +358,7 @@ q if {
359358
_, err := rego.New(
360359
rego.Module("error.rego", mod),
361360
rego.Query("data"),
362-
).PrepareForEval(context.Background())
361+
).PrepareForEval(t.Context())
363362

364363
expected := `{
365364
"errors": [

0 commit comments

Comments
 (0)