ci: bump golangci-lint (v2.9.0), fix issues

https://github.com/golangci/golangci-lint/releases/tag/v2.9.0

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This commit is contained in:
Stephan Renatus
2026-02-11 11:31:34 +01:00
committed by Stephan Renatus
parent b15601876e
commit 0d7e509613
35 changed files with 68 additions and 57 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ CONDITIONAL_WASM_TAG := -tags=opa_wasm
endif endif
override GO_TAGS := $(GO_TAGS) $(CONDITIONAL_WASM_TAG) override GO_TAGS := $(GO_TAGS) $(CONDITIONAL_WASM_TAG)
GOLANGCI_LINT_VERSION := v2.6.2 GOLANGCI_LINT_VERSION := v2.9.0
YAML_LINT_VERSION := 0.29.0 YAML_LINT_VERSION := 0.29.0
YAML_LINT_FORMAT ?= auto YAML_LINT_FORMAT ?= auto
+2 -1
View File
@@ -77,6 +77,7 @@ func TestBuildProducesBundle(t *testing.T) {
} }
func TestBuildRespectsCapabilities(t *testing.T) { func TestBuildRespectsCapabilities(t *testing.T) {
//nolint:prealloc // test slice is extended dynamically, initial values are clearer as slice literal
tests := []struct { tests := []struct {
note string note string
caps string caps string
@@ -3276,7 +3277,7 @@ Warning: .manifest file found in %q but -b flag not specified. Manifest will be
params.bundleMode = tc.bundleMode params.bundleMode = tc.bundleMode
params.stderr = &stderr params.stderr = &stderr
var args []string args := make([]string, 0, len(tc.buildArgs))
for _, arg := range tc.buildArgs { for _, arg := range tc.buildArgs {
args = append(args, path.Join(root, arg)) args = append(args, path.Join(root, arg))
} }
+1
View File
@@ -20,6 +20,7 @@ import (
) )
func TestCheckRespectsCapabilities(t *testing.T) { func TestCheckRespectsCapabilities(t *testing.T) {
//nolint:prealloc // test slice is extended dynamically, initial values are clearer as slice literal
tests := []struct { tests := []struct {
note string note string
caps string caps string
+2 -2
View File
@@ -1185,10 +1185,10 @@ func TestEvalWithStrictBuiltinErrors(t *testing.T) {
func assertResultSet(t *testing.T, rs rego.ResultSet, expected string) { func assertResultSet(t *testing.T, rs rego.ResultSet, expected string) {
t.Helper() t.Helper()
result := []any{} result := make([]any, 0, len(rs))
for i := range rs { for i := range rs {
values := []any{} values := make([]any, 0, len(rs[i].Expressions))
for j := range rs[i].Expressions { for j := range rs[i].Expressions {
values = append(values, rs[i].Expressions[j].Value) values = append(values, rs[i].Expressions[j].Value)
} }
+1 -1
View File
@@ -1187,7 +1187,7 @@ func testParse(t *testing.T, files map[string]string, params *parseParams) (int,
var tempDirUsed string var tempDirUsed string
test.WithTempFS(files, func(path string) { test.WithTempFS(files, func(path string) {
var args []string args := make([]string, 0, len(files))
for file := range files { for file := range files {
args = append(args, filepath.Join(path, file)) args = append(args, filepath.Join(path, file))
} }
+2 -2
View File
@@ -62,7 +62,7 @@ func TestGenerateBundleInfoWithFileDir(t *testing.T) {
t.Fatalf("expected namespaces %v, but got %v", expectedNamespaces, info.Namespaces) t.Fatalf("expected namespaces %v, but got %v", expectedNamespaces, info.Namespaces)
} }
var builtinNames []string builtinNames := make([]string, 0, len(info.Required.Builtins))
for _, bi := range info.Required.Builtins { for _, bi := range info.Required.Builtins {
builtinNames = append(builtinNames, bi.Name) builtinNames = append(builtinNames, bi.Name)
} }
@@ -250,7 +250,7 @@ func TestGenerateBundleInfoWithBundleTarGz(t *testing.T) {
t.Fatalf("expected namespaces %v, but got %v", expectedNamespaces, info.Namespaces) t.Fatalf("expected namespaces %v, but got %v", expectedNamespaces, info.Namespaces)
} }
expectedWasmModules := []map[string]any{} expectedWasmModules := make([]map[string]any, 0, 2)
expectedWasmModule1 := map[string]any{ expectedWasmModule1 := map[string]any{
"path": "/example/policy.wasm", "path": "/example/policy.wasm",
"url": filepath.Join(bundleFile, "example", "policy.wasm"), "url": filepath.Join(bundleFile, "example", "policy.wasm"),
+3 -2
View File
@@ -1285,6 +1285,7 @@ func (c *Compiler) compileScan(scan *ir.ScanStmt, result *[]instruction.Instruct
} }
func (c *Compiler) compileScanBlock(scan *ir.ScanStmt) ([]instruction.Instruction, error) { func (c *Compiler) compileScanBlock(scan *ir.ScanStmt) ([]instruction.Instruction, error) {
//nolint:prealloc // instruction list is known and fixed, clearer as slice literal
instrs := []instruction.Instruction{ instrs := []instruction.Instruction{
// Execute iterator. // Execute iterator.
instruction.GetLocal{Index: c.local(scan.Source)}, instruction.GetLocal{Index: c.local(scan.Source)},
@@ -1486,7 +1487,7 @@ func (c *Compiler) compileUpsert(local ir.Local, path []int, value ir.Operand, _
} }
func (c *Compiler) compileCallDynamicStmt(stmt *ir.CallDynamicStmt, result *[]instruction.Instruction) error { func (c *Compiler) compileCallDynamicStmt(stmt *ir.CallDynamicStmt, result *[]instruction.Instruction) error {
instrs := []instruction.Instruction{} instrs := make([]instruction.Instruction, 0, 3+3*len(stmt.Path)+len(stmt.Args)+10)
larray := c.genLocal() larray := c.genLocal()
lidx := c.genLocal() lidx := c.genLocal()
@@ -1559,7 +1560,7 @@ func (c *Compiler) compileCallStmt(stmt *ir.CallStmt, result *[]instruction.Inst
func (c *Compiler) compileInternalCall(stmt *ir.CallStmt, index uint32, result *[]instruction.Instruction) error { func (c *Compiler) compileInternalCall(stmt *ir.CallStmt, index uint32, result *[]instruction.Instruction) error {
instrs := []instruction.Instruction{} instrs := make([]instruction.Instruction, 0, len(stmt.Args)+4)
// Prepare function args and call. // Prepare function args and call.
for _, arg := range stmt.Args { for _, arg := range stmt.Args {
+2 -1
View File
@@ -16,7 +16,8 @@ func ClosestStrings(minDistance int, a string, candidates iter.Seq[string]) []st
levDist := levenshtein.ComputeDistance(a, c) levDist := levenshtein.ComputeDistance(a, c)
switch { switch {
case levDist < minDistance: case levDist < minDistance:
closestStrings = []string{c} closestStrings = make([]string, 1, 2)
closestStrings[0] = c
minDistance = levDist minDistance = levDist
case levDist == minDistance: case levDist == minDistance:
closestStrings = append(closestStrings, c) closestStrings = append(closestStrings, c)
+1 -1
View File
@@ -37,7 +37,7 @@ func TestWatchPaths(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
result := []string{} result := make([]string, 0, len(paths))
for _, p := range paths { for _, p := range paths {
result = append(result, filepath.Clean(strings.TrimPrefix(p, rootDir))) result = append(result, filepath.Clean(strings.TrimPrefix(p, rootDir)))
} }
+1 -1
View File
@@ -2070,7 +2070,7 @@ func (p *Planner) planRefDataExtent(virtual *ruletrie, base *baseptr, iter plani
} }
} }
if anyKeyNonGround { if anyKeyNonGround {
var rules []*ast.Rule rules := make([]*ast.Rule, 0, len(virtual.Children()))
for _, key := range virtual.Children() { for _, key := range virtual.Children() {
// TODO(sr): skip functions // TODO(sr): skip functions
rules = append(rules, virtual.Get(key).Rules()...) rules = append(rules, virtual.Get(key).Rules()...)
+6 -5
View File
@@ -544,7 +544,7 @@ func prettyProfile(w io.Writer, profile []profiler.ExprStats) error {
tableProfile := generateTableProfile(w) tableProfile := generateTableProfile(w)
for _, rs := range profile { for _, rs := range profile {
line := []string{} line := make([]string, 0, 5)
timeNs := time.Duration(rs.ExprTimeNs) * time.Nanosecond timeNs := time.Duration(rs.ExprTimeNs) * time.Nanosecond
timeNsStr := timeNs.String() timeNsStr := timeNs.String()
numEval := strconv.FormatInt(int64(rs.NumEval), 10) numEval := strconv.FormatInt(int64(rs.NumEval), 10)
@@ -695,13 +695,13 @@ func populateTableMetrics(m metrics.Metrics, table *tablewriter.Table, prettyLim
for varName, varValueInterface := range m.All() { for varName, varValueInterface := range m.All() {
val, ok := varValueInterface.(map[string]any) val, ok := varValueInterface.(map[string]any)
if !ok { if !ok {
line := []string{} line := make([]string, 0, 2)
varValue := checkStrLimit(fmt.Sprintf("%v", varValueInterface), prettyLimit) varValue := checkStrLimit(fmt.Sprintf("%v", varValueInterface), prettyLimit)
line = append(line, varName, varValue) line = append(line, varName, varValue)
lines = append(lines, line) lines = append(lines, line)
} else { } else {
for k, v := range val { for k, v := range val {
line := []string{} line := make([]string, 0, 2)
newVarName := fmt.Sprintf("%v_%v", varName, k) newVarName := fmt.Sprintf("%v_%v", varName, k)
value := checkStrLimit(fmt.Sprintf("%v", v), prettyLimit) value := checkStrLimit(fmt.Sprintf("%v", v), prettyLimit)
line = append(line, newVarName, value) line = append(line, newVarName, value)
@@ -718,9 +718,10 @@ func populateTableMetrics(m metrics.Metrics, table *tablewriter.Table, prettyLim
} }
func populateTableAggregatedMetrics(ms map[string]any, table *tablewriter.Table, prettyLimit int) (int, error) { func populateTableAggregatedMetrics(ms map[string]any, table *tablewriter.Table, prettyLimit int) (int, error) {
lines := [][]string{} lines := make([][]string, 0, len(ms))
for name, vals := range ms { for name, vals := range ms {
line := []string{name} line := make([]string, 0, 1+len(statKeys))
line = append(line, name)
vs := vals.(map[string]any) vs := vals.(map[string]any)
for _, k := range statKeys { for _, k := range statKeys {
line = append(line, checkStrLimit(fmt.Sprintf("%v", vs[k]), prettyLimit)) line = append(line, checkStrLimit(fmt.Sprintf("%v", vs[k]), prettyLimit))
+1 -1
View File
@@ -432,7 +432,7 @@ func TestWalkPaths(t *testing.T) {
test.WithTempFS(files, func(rootDir string) { test.WithTempFS(files, func(rootDir string) {
paths := []string{} paths := make([]string, 0, 2)
paths = append(paths, filepath.Join(rootDir, "bundle1"), filepath.Join(rootDir, "bundle2")) paths = append(paths, filepath.Join(rootDir, "bundle1"), filepath.Join(rootDir, "bundle2"))
// bundle mode // bundle mode
+1 -1
View File
@@ -27,7 +27,7 @@ func TestRoundTrip(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
modules := []*ast.Module{} modules := make([]*ast.Module, 0, len(c.Modules))
for _, m := range c.Modules { for _, m := range c.Modules {
modules = append(modules, m) modules = append(modules, m)
+1 -1
View File
@@ -974,7 +974,7 @@ func (c *Compiler) PassesTypeCheck(body Body) bool {
// PassesTypeCheckRules determines whether the given rules passes type checking // PassesTypeCheckRules determines whether the given rules passes type checking
func (c *Compiler) PassesTypeCheckRules(rules []*Rule) Errors { func (c *Compiler) PassesTypeCheckRules(rules []*Rule) Errors {
elems := []util.T{} elems := make([]util.T, 0, len(rules))
for _, rule := range rules { for _, rule := range rules {
elems = append(elems, rule) elems = append(elems, rule)
+2 -2
View File
@@ -5615,7 +5615,7 @@ func TestRewriteLocalVarDeclarationErrors(t *testing.T) {
sort.Strings(expectedErrors) sort.Strings(expectedErrors)
result := []string{} result := make([]string, 0, len(c.Errors))
for i := range c.Errors { for i := range c.Errors {
result = append(result, c.Errors[i].Message) result = append(result, c.Errors[i].Message)
@@ -11544,7 +11544,7 @@ foorule = true if {
} }
func compilerErrsToStringSlice(errors []*Error) []string { func compilerErrsToStringSlice(errors []*Error) []string {
result := []string{} result := make([]string, 0, len(errors))
for _, e := range errors { for _, e := range errors {
msg := strings.SplitN(e.Error(), ":", 3)[2] msg := strings.SplitN(e.Error(), ":", 3)[2]
result = append(result, strings.TrimSpace(msg)) result = append(result, strings.TrimSpace(msg))
+1 -1
View File
@@ -989,7 +989,7 @@ func (head *Head) HasDynamicRef() bool {
// Copy returns a deep copy of a. // Copy returns a deep copy of a.
func (a Args) Copy() Args { func (a Args) Copy() Args {
cpy := Args{} cpy := make(Args, 0, len(a))
for _, t := range a { for _, t := range a {
cpy = append(cpy, t.Copy()) cpy = append(cpy, t.Copy())
} }
+3 -3
View File
@@ -361,7 +361,7 @@ func TestAllOfSchemas(t *testing.T) {
func TestParseSchemaUntypedField(t *testing.T) { func TestParseSchemaUntypedField(t *testing.T) {
// Expected type is: object<foo: any> // Expected type is: object<foo: any>
staticProps := []*types.StaticProperty{} staticProps := make([]*types.StaticProperty, 0, 1)
staticProps = append(staticProps, &types.StaticProperty{Key: "foo", Value: types.A}) staticProps = append(staticProps, &types.StaticProperty{Key: "foo", Value: types.A})
expectedType := types.NewObject(staticProps, nil) expectedType := types.NewObject(staticProps, nil)
testParseSchema(t, untypedFieldObjectSchema, expectedType, nil) testParseSchema(t, untypedFieldObjectSchema, expectedType, nil)
@@ -375,7 +375,7 @@ func TestParseSchemaNoChildren(t *testing.T) {
func TestParseSchemaArrayNoItems(t *testing.T) { func TestParseSchemaArrayNoItems(t *testing.T) {
// Expected type is: object<b: array[any]> // Expected type is: object<b: array[any]>
staticProps := []*types.StaticProperty{} staticProps := make([]*types.StaticProperty, 0, 1)
staticProps = append(staticProps, &types.StaticProperty{Key: "b", Value: types.NewArray(nil, types.A)}) staticProps = append(staticProps, &types.StaticProperty{Key: "b", Value: types.NewArray(nil, types.A)})
expectedType := types.NewObject(staticProps, nil) expectedType := types.NewObject(staticProps, nil)
testParseSchema(t, arrayNoItemsSchema, expectedType, nil) testParseSchema(t, arrayNoItemsSchema, expectedType, nil)
@@ -383,7 +383,7 @@ func TestParseSchemaArrayNoItems(t *testing.T) {
func TestParseSchemaBooleanField(t *testing.T) { func TestParseSchemaBooleanField(t *testing.T) {
// Expected type is: object<a: boolean> // Expected type is: object<a: boolean>
staticProps := []*types.StaticProperty{} staticProps := make([]*types.StaticProperty, 0, 1)
staticProps = append(staticProps, &types.StaticProperty{Key: "a", Value: types.B}) staticProps = append(staticProps, &types.StaticProperty{Key: "a", Value: types.B})
expectedType := types.NewObject(staticProps, nil) expectedType := types.NewObject(staticProps, nil)
testParseSchema(t, booleanSchema, expectedType, nil) testParseSchema(t, booleanSchema, expectedType, nil)
+1 -1
View File
@@ -755,7 +755,7 @@ func TestRefExtend(t *testing.T) {
func TestRefConcat(t *testing.T) { func TestRefConcat(t *testing.T) {
a := MustParseRef("foo.bar.baz") a := MustParseRef("foo.bar.baz")
terms := []*Term{} terms := make([]*Term, 0, 2)
if !a.Concat(terms).Equal(a) { if !a.Concat(terms).Equal(a) {
t.Fatal("Expected no change") t.Fatal("Expected no change")
} }
+3 -3
View File
@@ -28,7 +28,7 @@ func TestGenerateSignedToken(t *testing.T) {
{"/data.json", `{"x": {"y": true}, "a": {"b": {"z": true}}}`}, {"/data.json", `{"x": {"y": true}, "a": {"b": {"z": true}}}`},
} }
input := []FileInfo{} input := make([]FileInfo, 0, len(files))
expDigests := make([]string, len(files)) expDigests := make([]string, len(files))
expDigests[0] = "a005c38a509dc2d5a7407b9494efb2ad" expDigests[0] = "a005c38a509dc2d5a7407b9494efb2ad"
@@ -77,7 +77,7 @@ func TestGenerateSignedTokenWithClaims(t *testing.T) {
{"/data.json", `{"x": {"y": true}, "a": {"b": {"z": true}}}}`}, {"/data.json", `{"x": {"y": true}, "a": {"b": {"z": true}}}}`},
} }
input := []FileInfo{} input := make([]FileInfo, 0, len(files))
expDigests := make([]string, len(files)) expDigests := make([]string, len(files))
expDigests[0] = "a005c38a509dc2d5a7407b9494efb2ad" expDigests[0] = "a005c38a509dc2d5a7407b9494efb2ad"
@@ -148,7 +148,7 @@ func TestGeneratePayload(t *testing.T) {
{"/.manifest", `{"revision": "quickbrownfaux"}`}, {"/.manifest", `{"revision": "quickbrownfaux"}`},
} }
input := []FileInfo{} input := make([]FileInfo, 0, 1)
file := FileInfo{ file := FileInfo{
Name: files[0][0], Name: files[0][0],
+1 -1
View File
@@ -3696,7 +3696,7 @@ func testWriteData(t *testing.T, tc testWriteModuleCase, legacy bool) {
// if supplied, pre-parse the module files // if supplied, pre-parse the module files
for _, b := range tc.bundles { for _, b := range tc.bundles {
var parsedMods []ModuleFile parsedMods := make([]ModuleFile, 0, len(b.Modules))
for _, mf := range b.Modules { for _, mf := range b.Modules {
parsedMods = append(parsedMods, ModuleFile{ parsedMods = append(parsedMods, ModuleFile{
Path: mf.Path, Path: mf.Path,
+3 -1
View File
@@ -3695,7 +3695,9 @@ type prettyBundle struct {
} }
func (p prettyBundle) String() string { func (p prettyBundle) String() string {
buf := []string{fmt.Sprintf("%d module(s) (hiding data):", len(p.Modules)), ""} buf := make([]string, 2, 2+len(p.Modules)*5)
buf[0] = fmt.Sprintf("%d module(s) (hiding data):", len(p.Modules))
buf[1] = ""
for _, mf := range p.Modules { for _, mf := range p.Modules {
buf = append(buf, buf = append(buf,
+5 -1
View File
@@ -90,7 +90,11 @@ func (bc *breakpointCollection) all() breakpointList {
bc.mtx.Lock() bc.mtx.Lock()
defer bc.mtx.Unlock() defer bc.mtx.Unlock()
var bps breakpointList count := 0
for _, list := range bc.breakpoints {
count += len(list)
}
bps := make(breakpointList, 0, count)
for _, list := range bc.breakpoints { for _, list := range bc.breakpoints {
bps = append(bps, list...) bps = append(bps, list...)
} }
+2 -1
View File
@@ -362,7 +362,8 @@ func TestDependencies(t *testing.T) {
// Test that we get the same result by analyzing all the // Test that we get the same result by analyzing all the
// rules separately. // rules separately.
var minRules, fullRules []ast.Ref minRules := make([]ast.Ref, 0, len(mod.Rules))
fullRules := make([]ast.Ref, 0, len(mod.Rules))
for _, rule := range mod.Rules { for _, rule := range mod.Rules {
m, f := runDeps(t, rule) m, f := runDeps(t, rule)
minRules = append(minRules, m...) minRules = append(minRules, m...)
+1 -1
View File
@@ -518,7 +518,7 @@ func TestChunkEncoderAdaptive(t *testing.T) {
func decodeChunks(t *testing.T, bs [][]byte) []EventV1 { func decodeChunks(t *testing.T, bs [][]byte) []EventV1 {
t.Helper() t.Helper()
var events []EventV1 events := make([]EventV1, 0, len(bs))
for _, chunk := range bs { for _, chunk := range bs {
e, err := newChunkDecoder(chunk).decode() e, err := newChunkDecoder(chunk).decode()
if err != nil { if err != nil {
+1 -1
View File
@@ -57,7 +57,7 @@ func (p *Profiler) ReportByFile() Report {
report := Report{Files: map[string]*FileReport{}} report := Report{Files: map[string]*FileReport{}}
for file, hits := range p.hits { for file, hits := range p.hits {
stats := []ExprStats{} stats := make([]ExprStats, 0, len(hits))
for row, stat := range hits { for row, stat := range hits {
if entry, ok := p.hitsByExprIndex[file][row]; ok { if entry, ok := p.hitsByExprIndex[file][row]; ok {
stat.NumGenExpr = len(entry) stat.NumGenExpr = len(entry)
+2 -2
View File
@@ -414,10 +414,10 @@ func assertPreparedEvalQueryEval(t *testing.T, pq PreparedEvalQuery, options []E
func assertResultSet(t *testing.T, rs ResultSet, expected string) { func assertResultSet(t *testing.T, rs ResultSet, expected string) {
t.Helper() t.Helper()
result := []any{} result := make([]any, 0, len(rs))
for i := range rs { for i := range rs {
values := []any{} values := make([]any, 0, len(rs[i].Expressions))
for j := range rs[i].Expressions { for j := range rs[i].Expressions {
values = append(values, rs[i].Expressions[j].Value) values = append(values, rs[i].Expressions[j].Value)
} }
+1 -1
View File
@@ -1485,7 +1485,7 @@ func printHelpCommands(output io.Writer) {
all := append(extra[:], builtin[:]...) all := append(extra[:], builtin[:]...)
// Compute max length of all command and topic names. // Compute max length of all command and topic names.
names := []string{} names := make([]string, 0, len(all)+len(topics))
for _, x := range all { for _, x := range all {
names = append(names, x.syntax()) names = append(names, x.syntax())
+1
View File
@@ -167,6 +167,7 @@ func (opa *OPA) configure(ctx context.Context, bs []byte, ready chan struct{}, b
return err return err
} }
//nolint:prealloc // option list has known initial values, extended with opa.managerOpts
opts := []func(*plugins.Manager){ opts := []func(*plugins.Manager){
plugins.Info(info), plugins.Info(info),
plugins.Logger(opa.logger), plugins.Logger(opa.logger),
+1 -1
View File
@@ -726,7 +726,7 @@ func TestRunnerWithCustomBuiltin(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
var results []*tester.Result results := make([]*tester.Result, 0, 10)
for r := range ch { for r := range ch {
results = append(results, r) results = append(results, r)
+6 -6
View File
@@ -51,7 +51,7 @@ type Person struct {
func TestHTTPGetRequest(t *testing.T) { func TestHTTPGetRequest(t *testing.T) {
t.Parallel() t.Parallel()
var people []Person people := make([]Person, 0, 1)
// test data // test data
people = append(people, Person{ID: "1", Firstname: "John"}) people = append(people, Person{ID: "1", Firstname: "John"})
@@ -71,7 +71,7 @@ func TestHTTPGetRequest(t *testing.T) {
expectedResult["status"] = "200 OK" expectedResult["status"] = "200 OK"
expectedResult["status_code"] = http.StatusOK expectedResult["status_code"] = http.StatusOK
var body []any body := make([]any, 0, 1)
bodyMap := map[string]string{"id": "1", "firstname": "John"} bodyMap := map[string]string{"id": "1", "firstname": "John"}
body = append(body, bodyMap) body = append(body, bodyMap)
expectedResult["body"] = body expectedResult["body"] = body
@@ -122,7 +122,7 @@ func TestHTTPGetRequestTlsInsecureSkipVerify(t *testing.T) {
"status_code": http.StatusOK, "status_code": http.StatusOK,
} }
var body []any body := make([]any, 0, 1)
bodyMap := map[string]string{"id": "1", "firstname": "John"} bodyMap := map[string]string{"id": "1", "firstname": "John"}
body = append(body, bodyMap) body = append(body, bodyMap)
expectedResult["body"] = body expectedResult["body"] = body
@@ -558,7 +558,7 @@ func TestHTTPDeleteRequest(t *testing.T) {
expectedResult["status"] = "200 OK" expectedResult["status"] = "200 OK"
expectedResult["status_code"] = http.StatusOK expectedResult["status_code"] = http.StatusOK
var body []any body := make([]any, 0, 1)
bodyMap := map[string]string{"id": "1", "firstname": "John"} bodyMap := map[string]string{"id": "1", "firstname": "John"}
body = append(body, bodyMap) body = append(body, bodyMap)
expectedResult["body"] = body expectedResult["body"] = body
@@ -3555,7 +3555,7 @@ var httpSendHelperRules = []string{
func TestSocketHTTPGetRequest(t *testing.T) { func TestSocketHTTPGetRequest(t *testing.T) {
t.Parallel() t.Parallel()
var people []Person people := make([]Person, 0, 1)
// test data // test data
people = append(people, Person{ID: "1", Firstname: "John"}) people = append(people, Person{ID: "1", Firstname: "John"})
@@ -3598,7 +3598,7 @@ func TestSocketHTTPGetRequest(t *testing.T) {
expectedResult["status"] = "200 OK" expectedResult["status"] = "200 OK"
expectedResult["status_code"] = http.StatusOK expectedResult["status_code"] = http.StatusOK
var body []any body := make([]any, 0, 1)
bodyMap := map[string]string{"id": "1", "firstname": "John"} bodyMap := map[string]string{"id": "1", "firstname": "John"}
body = append(body, bodyMap) body = append(body, bodyMap)
expectedResult["body"] = body expectedResult["body"] = body
+1 -1
View File
@@ -366,7 +366,7 @@ func genRandom3LayerObjectJSONPatchListData(l1Keys, l2Keys, l3Keys, p int) ast.V
depth := rand.Intn(3) + 1 // (max - min) + min method of getting a random range. depth := rand.Intn(3) + 1 // (max - min) + min method of getting a random range.
// Random values for each path segment. // Random values for each path segment.
segments := []string{} segments := make([]string, 0, 2*depth)
for j := range depth { for j := range depth {
pathSegment := strconv.FormatInt(int64(rand.Intn(numKeys[j])), 10) pathSegment := strconv.FormatInt(int64(rand.Intn(numKeys[j])), 10)
segments = append(segments, "/", pathSegment) segments = append(segments, "/", pathSegment)
+2 -4
View File
@@ -388,12 +388,10 @@ func TestTopDownJWTEncodeSignES512(t *testing.T) {
note string note string
rules []string rules []string
} }
var tests []test tests := []test{{
tests = append(tests, test{
params.note, params.note,
[]string{fmt.Sprintf(`p = x { io.jwt.encode_sign_raw(%s, %s, %s, x) }`, params.input1, params.input2, params.input3)}, []string{fmt.Sprintf(`p = x { io.jwt.encode_sign_raw(%s, %s, %s, x) }`, params.input1, params.input2, params.input3)},
}) }}
tc := tests[0] tc := tests[0]
+4 -4
View File
@@ -1946,7 +1946,7 @@ func compileModules(input []string) *ast.Compiler {
func compileRules(imports []string, input []string, modules []string) (*ast.Compiler, error) { func compileRules(imports []string, input []string, modules []string) (*ast.Compiler, error) {
is := []*ast.Import{} is := make([]*ast.Import, 0, len(imports))
for _, i := range imports { for _, i := range imports {
is = append(is, &ast.Import{ is = append(is, &ast.Import{
Path: ast.MustParseTerm(i), Path: ast.MustParseTerm(i),
@@ -1960,7 +1960,7 @@ func compileRules(imports []string, input []string, modules []string) (*ast.Comp
Imports: is, Imports: is,
} }
rules := []*ast.Rule{} rules := make([]*ast.Rule, 0, len(input))
for i := range input { for i := range input {
rules = append(rules, ast.MustParseRuleWithOpts(input[i], popts)) rules = append(rules, ast.MustParseRuleWithOpts(input[i], popts))
rules[i].Module = m rules[i].Module = m
@@ -2096,7 +2096,7 @@ func runTopDownTestCaseWithContext(ctx context.Context, t *testing.T, data map[s
options ...func(*Query) *Query) { options ...func(*Query) *Query) {
t.Helper() t.Helper()
imports := []string{} imports := make([]string, 0, len(data))
for k := range data { for k := range data {
imports = append(imports, "data."+k) imports = append(imports, "data."+k)
} }
@@ -2381,7 +2381,7 @@ func getTestNamespace() string {
func dump(note string, modules map[string]*ast.Module, data any, docpath []string, input *ast.Term, exp any, requiresSort bool) { func dump(note string, modules map[string]*ast.Module, data any, docpath []string, input *ast.Term, exp any, requiresSort bool) {
moduleSet := []string{} moduleSet := make([]string, 0, len(modules))
for _, module := range modules { for _, module := range modules {
moduleSet = append(moduleSet, string(bytes.ReplaceAll(format.MustAst(module), []byte("\t"), []byte(" ")))) moduleSet = append(moduleSet, string(bytes.ReplaceAll(format.MustAst(module), []byte("\t"), []byte(" "))))
} }
+1 -1
View File
@@ -219,7 +219,7 @@ func (t *Array) toMap() map[string]any {
func (t *Array) String() string { func (t *Array) String() string {
prefix := "array" prefix := "array"
buf := []string{} buf := make([]string, 0, len(t.static))
for _, tpe := range t.static { for _, tpe := range t.static {
buf = append(buf, Sprint(tpe)) buf = append(buf, Sprint(tpe))
} }
+1 -1
View File
@@ -27,7 +27,7 @@ func newTestTraversal(g map[int][]int) *testTraversal {
} }
func (t *testTraversal) Edges(x T) []T { func (t *testTraversal) Edges(x T) []T {
r := []T{} r := make([]T, 0, len(t.g[x.(int)]))
for _, v := range t.g[x.(int)] { for _, v := range t.g[x.(int)] {
r = append(r, v) r = append(r, v)
} }