Modernize code for Go 1.24

Brought to you by

	modernize -fix -test ./...

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-08-13 20:17:05 -07:00
parent b042b6d455
commit 89e59902c4
14 changed files with 17 additions and 25 deletions
+1 -1
View File
@@ -132,7 +132,7 @@ func getSubCgroupPaths(args []string) (map[string]string, error) {
// Split into controller:path.
if ctr, path, ok := strings.Cut(c, ":"); ok {
// There may be a few comma-separated controllers.
for _, ctrl := range strings.Split(ctr, ",") {
for ctrl := range strings.SplitSeq(ctr, ",") {
if ctrl == "" {
return nil, fmt.Errorf("invalid --cgroup argument: %s (empty <controller> prefix)", c)
}
+1 -1
View File
@@ -325,7 +325,7 @@ func toCPUSet(str string) (*unix.CPUSet, error) {
return int(ret), nil
}
for _, r := range strings.Split(str, ",") {
for r := range strings.SplitSeq(str, ",") {
// Allow extra spaces around.
r = strings.TrimSpace(r)
// Allow empty elements (extra commas).
+1 -1
View File
@@ -30,7 +30,7 @@ func TestUnmarshalHooks(t *testing.T) {
for _, hookName := range configs.HookNameList {
hooks := configs.Hooks{}
err = hooks.UnmarshalJSON([]byte(fmt.Sprintf(`{"%s" :[%s]}`, hookName, hookJson)))
err = hooks.UnmarshalJSON(fmt.Appendf(nil, `{"%s" :[%s]}`, hookName, hookJson))
if err != nil {
t.Fatal(err)
}
-1
View File
@@ -57,7 +57,6 @@ func TestToCPUSet(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.in, func(t *testing.T) {
out, err := toCPUSet(tc.in)
t.Logf("toCPUSet(%q) = %v (error: %v)", tc.in, out, err)
+1 -1
View File
@@ -60,7 +60,7 @@ func rootlessEUIDMount(config *configs.Config) error {
if !strings.Contains(mount.Data, "id=") {
continue
}
for _, opt := range strings.Split(mount.Data, ",") {
for opt := range strings.SplitSeq(mount.Data, ",") {
if str, ok := strings.CutPrefix(opt, "uid="); ok {
uid, err := strconv.Atoi(str)
if err != nil {
@@ -154,8 +154,7 @@ func BenchmarkRootlessEUIDMount(b *testing.B) {
},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
err := rootlessEUIDMount(config)
if err != nil {
b.Fatal(err)
@@ -774,7 +774,6 @@ func TestValidateIDMapMounts(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
config := tc.config
config.Rootfs = "/var"
+2 -4
View File
@@ -34,8 +34,7 @@ func BenchmarkExecTrue(b *testing.B) {
}()
ok(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
exec := &libcontainer.Process{
Cwd: "/",
Args: []string{"/bin/true"},
@@ -101,8 +100,7 @@ func BenchmarkExecInBigEnv(b *testing.B) {
wantOut.WriteString(e + "\n")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
buffers := newStdBuffers()
exec := &libcontainer.Process{
Cwd: "/",
+6 -6
View File
@@ -850,8 +850,8 @@ func TestMountCgroupRO(t *testing.T) {
buffers := runContainerOk(t, config, "mount")
mountInfo := buffers.Stdout.String()
lines := strings.Split(mountInfo, "\n")
for _, l := range lines {
lines := strings.SplitSeq(mountInfo, "\n")
for l := range lines {
if strings.HasPrefix(l, "tmpfs on /sys/fs/cgroup") {
if !strings.Contains(l, "ro") ||
!strings.Contains(l, "nosuid") ||
@@ -892,8 +892,8 @@ func TestMountCgroupRW(t *testing.T) {
buffers := runContainerOk(t, config, "mount")
mountInfo := buffers.Stdout.String()
lines := strings.Split(mountInfo, "\n")
for _, l := range lines {
lines := strings.SplitSeq(mountInfo, "\n")
for l := range lines {
if strings.HasPrefix(l, "tmpfs on /sys/fs/cgroup") {
if !strings.Contains(l, "rw") ||
!strings.Contains(l, "nosuid") ||
@@ -1206,8 +1206,8 @@ func TestRootfsPropagationSlaveMount(t *testing.T) {
dir2cont = filepath.Join(dir1cont, filepath.Base(dir2host))
propagationInfo := stdout2.String()
lines := strings.Split(propagationInfo, "\n")
for _, l := range lines {
lines := strings.SplitSeq(propagationInfo, "\n")
for l := range lines {
linefields := strings.Split(l, " ")
if len(linefields) < 5 {
continue
@@ -42,7 +42,7 @@ func BenchmarkSpawnProc(b *testing.B) {
}
})
for i := 0; i < b.N; i++ {
for b.Loop() {
proc, err := spawnProc(mapping)
if err != nil {
b.Error(err)
+1 -1
View File
@@ -354,7 +354,7 @@ func mountCgroupV1(m *configs.Mount, c *mountConfig) error {
}
}
for _, mc := range merged {
for _, ss := range strings.Split(mc, ",") {
for ss := range strings.SplitSeq(mc, ",") {
// symlink(2) is very dumb, it will just shove the path into
// the link and doesn't do any checks or relative path
// conversion. Also, don't error out if the cgroup already exists.
+1 -2
View File
@@ -777,7 +777,6 @@ func TestInitSystemdProps(t *testing.T) {
spec := &specs.Spec{}
for _, tc := range testCases {
tc := tc
spec.Annotations = map[string]string{tc.in.name: tc.in.value}
outMap, err := initSystemdProps(spec)
@@ -834,7 +833,7 @@ func TestCheckPropertyName(t *testing.T) {
}
func BenchmarkCheckPropertyName(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
for _, s := range []string{"", "xx", "xxx", "someValidName", "A name", "Кир", "მადლობა", "合い言葉"} {
_ = checkPropertyName(s)
}
@@ -67,7 +67,6 @@ func TestParseRelease(t *testing.T) {
{in: "3.-8", expectedErr: fmt.Errorf(`failed to parse kernel version "3.-8": expected integer`)},
}
for _, tc := range tests {
tc := tc
t.Run(tc.in, func(t *testing.T) {
version, err := parseRelease(tc.in)
if tc.expectedErr != nil {
@@ -126,7 +125,6 @@ func TestGreaterEqualThan(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.doc+": "+tc.in.String(), func(t *testing.T) {
ok, err := GreaterEqualThan(tc.in)
if err != nil {
+1 -1
View File
@@ -128,7 +128,7 @@ func (s *notifySocket) run(pid1 int) error {
got := buf[0:r]
// systemd-ready sends a single datagram with the state string as payload,
// so we don't need to worry about partial messages.
for _, line := range bytes.Split(got, []byte{'\n'}) {
for line := range bytes.SplitSeq(got, []byte{'\n'}) {
if bytes.HasPrefix(got, []byte("READY=")) {
fileChan <- line
return