Skip to content

Commit c3dd462

Browse files
committed
Modernize the code for Go 1.24
Mostly done by modernize -fix -test ./... with some minor manual edits on top. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 5ae4a33 commit c3dd462

18 files changed

+19
-31
lines changed

devices/devicefilter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func hash(s, comm string) string {
1111
var res []string
12-
for _, l := range strings.Split(s, "\n") {
12+
for l := range strings.SplitSeq(s, "\n") {
1313
trimmed := strings.TrimSpace(l)
1414
if trimmed == "" || strings.HasPrefix(trimmed, comm) {
1515
continue

devices/devices_emulator_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ c 10:200 rwm`,
202202
}
203203

204204
for _, test := range tests {
205-
test := test // capture range variable
206205
t.Run(test.name, func(t *testing.T) {
207206
list := bytes.NewBufferString(test.list)
208207
emu, err := emulatorFromList(list)
@@ -741,7 +740,6 @@ func testDeviceEmulatorApply(t *testing.T, baseDefaultAllow bool) {
741740
}
742741

743742
for _, test := range tests {
744-
test := test
745743
t.Run(test.name, func(t *testing.T) {
746744
err := test.base.Apply(test.rule)
747745
if err != nil && test.expected != nil {
@@ -1058,7 +1056,6 @@ func testDeviceEmulatorTransition(t *testing.T, sourceDefaultAllow bool) {
10581056
}
10591057

10601058
for _, test := range tests {
1061-
test := test
10621059
t.Run(test.name, func(t *testing.T) {
10631060
// If we are in black-list mode, we need to prepend the relevant
10641061
// clear-all rule (the expected rule lists are written with
@@ -1130,7 +1127,7 @@ c 10:200 rwm`
11301127

11311128
var r *deviceRule
11321129
var err error
1133-
for i := 0; i < b.N; i++ {
1130+
for b.Loop() {
11341131
s := bufio.NewScanner(strings.NewReader(list))
11351132
for s.Scan() {
11361133
line := s.Text()

devices/systemd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestFindDeviceGroup(t *testing.T) {
256256
}
257257

258258
func BenchmarkFindDeviceGroup(b *testing.B) {
259-
for i := 0; i < b.N; i++ {
259+
for b.Loop() {
260260
if err := testFindDeviceGroup(); err != nil {
261261
b.Fatal(err)
262262
}

file_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ func BenchmarkWriteFile(b *testing.B) {
8282
"\n\n\n\n\n\n\n\n",
8383
}
8484

85-
b.ResetTimer()
86-
for i := 0; i < b.N; i++ {
85+
for b.Loop() {
8786
for _, val := range tc {
8887
if err := WriteFileByLine(dir, "file", val); err != nil {
8988
b.Fatal(err)

fs/cpuacct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func getPercpuUsage(path string) ([]uint64, error) {
105105
if err != nil {
106106
return percpuUsage, err
107107
}
108-
for _, value := range strings.Fields(data) {
108+
for value := range strings.FieldsSeq(data) {
109109
value, err := strconv.ParseUint(value, 10, 64)
110110
if err != nil {
111111
return percpuUsage, &parseError{Path: path, File: file, Err: err}

fs/cpuacct_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ func BenchmarkGetCpuUsageBreakdown(b *testing.B) {
102102
"cpuacct.stat": cpuAcctStatContents,
103103
})
104104

105-
b.ResetTimer()
106-
for i := 0; i < b.N; i++ {
105+
for b.Loop() {
107106
_, _, err := getCpuUsageBreakdown(path)
108107
if err != nil {
109108
b.Fatal(err)

fs/cpuset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func getCpusetStat(path string, file string) ([]uint16, error) {
8282
return extracted, &parseError{Path: path, File: file, Err: errors.New("empty file")}
8383
}
8484

85-
for _, s := range strings.Split(fileContent, ",") {
85+
for s := range strings.SplitSeq(fileContent, ",") {
8686
fromStr, toStr, ok := strings.Cut(s, "-")
8787
if ok {
8888
from, err := strconv.ParseUint(fromStr, 10, 16)

fs/fs_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ func BenchmarkGetStats(b *testing.B) {
3636

3737
var st *cgroups.Stats
3838

39-
b.ResetTimer()
40-
for i := 0; i < b.N; i++ {
39+
for b.Loop() {
4140
st, err = m.GetStats()
4241
if err != nil {
4342
b.Fatal(err)

fs2/create.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func needAnyControllers(r *cgroups.Resources) (bool, error) {
2828
return false, err
2929
}
3030
avail := make(map[string]struct{})
31-
for _, ctr := range strings.Fields(content) {
31+
for ctr := range strings.FieldsSeq(content) {
3232
avail[ctr] = struct{}{}
3333
}
3434

@@ -137,8 +137,7 @@ func CreateCgroupPath(path string, c *cgroups.Cgroup) (Err error) {
137137
if i < len(elements)-1 {
138138
if err := cgroups.WriteFile(current, cgStCtlFile, res); err != nil {
139139
// try write one by one
140-
allCtrs := strings.Split(res, " ")
141-
for _, ctr := range allCtrs {
140+
for ctr := range strings.SplitSeq(res, " ") {
142141
_ = cgroups.WriteFile(current, cgStCtlFile, ctr)
143142
}
144143
}

fscommon/utils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ func GetValueByKey(path, file, key string) (uint64, error) {
8282
}
8383

8484
key += " "
85-
lines := strings.Split(content, "\n")
86-
for _, line := range lines {
85+
for line := range strings.SplitSeq(content, "\n") {
8786
v, ok := strings.CutPrefix(line, key)
8887
if ok {
8988
val, err := ParseUint(v, 10, 64)

0 commit comments

Comments
 (0)