Merge pull request #51722 from vvoland/modernize

Modernize Go code
This commit is contained in:
Paweł Gronowski
2025-12-16 12:38:36 +00:00
committed by GitHub
157 changed files with 464 additions and 633 deletions

View File

@@ -33,7 +33,7 @@ func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B)
outerGroup.Add(maxConcurrency)
chErr := make(chan error, numIterations*2*maxConcurrency)
for i := 0; i < maxConcurrency; i++ {
for range maxConcurrency {
go func() {
defer outerGroup.Done()
innerGroup := &sync.WaitGroup{}
@@ -41,7 +41,7 @@ func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B)
go func() {
defer innerGroup.Done()
for i := 0; i < numIterations; i++ {
for range numIterations {
args := []string{"run", "-d", "busybox"}
args = append(args, sleepCommandForDaemonPlatform()...)
out, _, err := dockerCmdWithError(args...)
@@ -88,7 +88,7 @@ func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B)
go func() {
defer innerGroup.Done()
for i := 0; i < numIterations; i++ {
for range numIterations {
out, _, err := dockerCmdWithError("ps")
if err != nil {
chErr <- errors.New(out)

View File

@@ -200,7 +200,7 @@ func (d *Daemon) CmdRetryOutOfSequence(args ...string) (string, error) {
err error
)
for i := 0; i < 10; i++ {
for range 10 {
output, err = d.Cmd(args...)
// error, no error, whatever. if we don't have "update out of
// sequence", we don't retry, we just return.

View File

@@ -569,7 +569,7 @@ type buildLine struct {
func getImageIDsFromBuild(t *testing.T, output []byte) []string {
var ids []string
for _, line := range bytes.Split(output, []byte("\n")) {
for line := range bytes.SplitSeq(output, []byte("\n")) {
if len(line) == 0 {
continue
}

View File

@@ -92,7 +92,7 @@ func (s *DockerAPISuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) {
ch = make(chan error, n)
wg sync.WaitGroup
)
for i := 0; i < n; i++ {
for range n {
wg.Add(1)
go func() {
defer wg.Done()

View File

@@ -125,7 +125,7 @@ func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
go func() {
bufReader := bufio.NewReader(reader)
defer reader.Close()
for i := 0; i < untilSecs; i++ {
for range untilSecs {
out, _, err := bufReader.ReadLine()
if err != nil {
if err == io.EOF {
@@ -148,7 +148,7 @@ func (s *DockerAPISuite) TestLogsAPIUntilFutureFollow(c *testing.T) {
}
}()
for i := 0; i < untilSecs; i++ {
for range untilSecs {
select {
case l := <-chLog:
assert.NilError(c, l.err)

View File

@@ -149,7 +149,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *testing.T) {
ctx := testutil.GetContext(c)
const nodeCount = 3
var daemons [nodeCount]*daemon.Daemon
for i := 0; i < nodeCount; i++ {
for i := range nodeCount {
daemons[i] = s.AddDaemon(ctx, c, true, i == 0)
}
// wait for nodes ready
@@ -305,7 +305,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {
ctx := testutil.GetContext(c)
const nodeCount = 3
var daemons [nodeCount]*daemon.Daemon
for i := 0; i < nodeCount; i++ {
for i := range nodeCount {
daemons[i] = s.AddDaemon(ctx, c, true, i == 0)
}
// wait for nodes ready
@@ -344,7 +344,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {
ctx := testutil.GetContext(c)
const nodeCount = 3
var daemons [nodeCount]*daemon.Daemon
for i := 0; i < nodeCount; i++ {
for i := range nodeCount {
daemons[i] = s.AddDaemon(ctx, c, true, i == 0)
}
// wait for nodes ready
@@ -397,7 +397,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {
ctx := testutil.GetContext(c)
const nodeCount = 3
var daemons [nodeCount]*daemon.Daemon
for i := 0; i < nodeCount; i++ {
for i := range nodeCount {
daemons[i] = s.AddDaemon(ctx, c, true, i == 0)
}
// wait for nodes ready
@@ -494,7 +494,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *testing.T) {
const nodeCount = 3
var daemons [nodeCount]*daemon.Daemon
for i := 0; i < nodeCount; i++ {
for i := range nodeCount {
daemons[i] = s.AddDaemon(ctx, c, true, i == 0)
}
// wait for nodes ready

View File

@@ -815,7 +815,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *testing.T) {
mCount, wCount := 5, 1
var nodes []*daemon.Daemon
for i := 0; i < mCount; i++ {
for range mCount {
manager := s.AddDaemon(ctx, c, true, true)
info := manager.SwarmInfo(ctx, c)
assert.Equal(c, info.ControlAvailable, true)
@@ -823,7 +823,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *testing.T) {
nodes = append(nodes, manager)
}
for i := 0; i < wCount; i++ {
for range wCount {
worker := s.AddDaemon(ctx, c, true, false)
info := worker.SwarmInfo(ctx, c)
assert.Equal(c, info.ControlAvailable, false)
@@ -959,7 +959,7 @@ func (s *DockerSwarmSuite) TestSwarmRepeatedRootRotation(c *testing.T) {
currentTrustRoot := info.Cluster.TLSInfo.TrustRoot
// rotate multiple times
for i := 0; i < 4; i++ {
for i := range 4 {
var err error
var cert, key []byte
if i%2 != 0 {
@@ -979,7 +979,7 @@ func (s *DockerSwarmSuite) TestSwarmRepeatedRootRotation(c *testing.T) {
// poll to make sure update succeeds
var clusterTLSInfo swarm.TLSInfo
for j := 0; j < 18; j++ {
for range 18 {
info := m.SwarmInfo(ctx, c)
// the desired CA cert and key is always redacted
@@ -1001,7 +1001,7 @@ func (s *DockerSwarmSuite) TestSwarmRepeatedRootRotation(c *testing.T) {
}
// could take another second or two for the nodes to trust the new roots after they've all gotten
// new TLS certificates
for j := 0; j < 18; j++ {
for range 18 {
mInfo := m.GetNode(ctx, c, m.NodeID()).Description.TLSInfo
wInfo := m.GetNode(ctx, c, w.NodeID()).Description.TLSInfo

View File

@@ -54,7 +54,7 @@ func (s *DockerCLIAttachSuite) TestAttachMultipleAndRestart(c *testing.T) {
close(startDone)
}()
for i := 0; i < 3; i++ {
for range 3 {
go func() {
cmd := exec.Command(dockerBinary, "attach", "attacher")

View File

@@ -12,6 +12,7 @@ import (
"reflect"
"regexp"
"runtime"
"slices"
"strconv"
"strings"
"testing"
@@ -1590,8 +1591,8 @@ func (s *DockerCLIBuildSuite) TestBuildExposeMorePorts(c *testing.T) {
portList := make([]string, 50)
line := make([]string, 100)
expectedPorts := make([]int, len(portList)*len(line))
for i := 0; i < len(portList); i++ {
for j := 0; j < len(line); j++ {
for i := range portList {
for j := range line {
p := i*len(line) + j + 1
line[j] = strconv.Itoa(p)
expectedPorts[p-1] = p
@@ -4357,13 +4358,7 @@ func (s *DockerCLIBuildSuite) TestBuildBuildTimeArgExpansion(c *testing.T) {
var resArr []string
inspectFieldAndUnmarshall(c, imgName, "Config.Env", &resArr)
found := false
for _, v := range resArr {
if fmt.Sprintf("%s=%s", envVar, envVal) == v {
found = true
break
}
}
found := slices.Contains(resArr, fmt.Sprintf("%s=%s", envVar, envVal))
if !found {
c.Fatalf("Config.Env value mismatch. Expected <key=value> to exist: %s=%s, got: %v",
envVar, envVal, resArr)
@@ -4707,11 +4702,8 @@ func (s *DockerCLIBuildSuite) TestBuildTagEvent(c *testing.T) {
events := strings.Split(strings.TrimSpace(out), "\n")
actions := eventActionsByIDAndType(c, events, imgName+":latest", "image")
var foundTag bool
for _, a := range actions {
if a == "tag" {
foundTag = true
break
}
if slices.Contains(actions, "tag") {
foundTag = true
}
assert.Assert(c, foundTag, "No tag event found:\n%s", out)
@@ -5645,7 +5637,7 @@ func (s *DockerCLIBuildSuite) TestBuildMultiStageCopyFromSyntax(c *testing.T) {
assert.Equal(c, strings.Count(result.Combined(), "Using cache"), 7)
assert.Equal(c, getIDByName(c, "build1"), getIDByName(c, "build2"))
err := os.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(fmt.Sprintf(dockerfile, "COPY baz/aa foo")), 0o644)
err := os.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), fmt.Appendf(nil, dockerfile, "COPY baz/aa foo"), 0o644)
assert.NilError(c, err)
// changing file in parent block should not affect last block

View File

@@ -1127,7 +1127,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *testing.T)
maxChildren := 10
chErr := make(chan error, maxChildren)
for i := 0; i < maxChildren; i++ {
for i := range maxChildren {
wg.Add(1)
name := fmt.Sprintf("test%d", i)
@@ -2125,7 +2125,7 @@ func (s *DockerDaemonSuite) TestShmSizeReload(c *testing.T) {
configFile := filepath.Join(configPath, "config.json")
size := 67108864 * 2
configData := []byte(fmt.Sprintf(`{"default-shm-size": "%dM"}`, size/1024/1024))
configData := fmt.Appendf(nil, `{"default-shm-size": "%dM"}`, size/1024/1024)
assert.Assert(c, os.WriteFile(configFile, configData, 0o666) == nil, "could not write temp file for config reload")
pattern := regexp.MustCompile(fmt.Sprintf("shm on /dev/shm type tmpfs(.*)size=%dk", size/1024))
@@ -2140,7 +2140,7 @@ func (s *DockerDaemonSuite) TestShmSizeReload(c *testing.T) {
assert.Equal(c, strings.TrimSpace(out), fmt.Sprintf("%v", size))
size = 67108864 * 3
configData = []byte(fmt.Sprintf(`{"default-shm-size": "%dM"}`, size/1024/1024))
configData = fmt.Appendf(nil, `{"default-shm-size": "%dM"}`, size/1024/1024)
assert.Assert(c, os.WriteFile(configFile, configData, 0o666) == nil, "could not write temp file for config reload")
pattern = regexp.MustCompile(fmt.Sprintf("shm on /dev/shm type tmpfs(.*)size=%dk", size/1024))

View File

@@ -283,7 +283,7 @@ func (s *DockerCLIExecSuite) TestExecCgroup(c *testing.T) {
var execCgroups []sort.StringSlice
errChan := make(chan error, 5)
// exec a few times concurrently to get consistent failure
for i := 0; i < 5; i++ {
for range 5 {
wg.Add(1)
go func() {
defer wg.Done()
@@ -337,7 +337,7 @@ func (s *DockerCLIExecSuite) TestExecInspectID(c *testing.T) {
// Give the exec 10 chances/seconds to start then give up and stop the test
tries := 10
for i := 0; i < tries; i++ {
for i := range tries {
// Since its still running we should see exec as part of the container
out = strings.TrimSpace(inspectField(c, id, "ExecIDs"))
@@ -360,7 +360,7 @@ func (s *DockerCLIExecSuite) TestExecInspectID(c *testing.T) {
cmd.Wait()
// Give the exec 10 chances/seconds to stop then give up and stop the test
for i := 0; i < tries; i++ {
for i := range tries {
// Since its still running we should see exec as part of the container
out = strings.TrimSpace(inspectField(c, id, "ExecIDs"))

View File

@@ -547,7 +547,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverCapabilities(c *test
s.d.Start(c)
assert.Equal(c, s.ec.caps, 0)
for i := 0; i < 3; i++ {
for i := range 3 {
out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, fmt.Sprintf("test%d", i))
assert.NilError(c, err, out)
assert.Equal(c, s.ec.caps, 1)

View File

@@ -62,7 +62,7 @@ LABEL label.Z="Z"`))
actualValues := strings.Split(out, "\n")[1:27]
expectedValues := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"}
for i := 0; i < 26; i++ {
for i := range 26 {
echoValue := fmt.Sprintf("LABEL label.%s=%s", expectedValues[i], expectedValues[i])
actualValue := actualValues[i]
assert.Assert(c, is.Contains(actualValue, echoValue))

View File

@@ -199,8 +199,8 @@ func (s *DockerCLIImagesSuite) TestImagesFilterSinceAndBefore(c *testing.T) {
func getImageIDs(out string) []string {
var actual []string
imgs := strings.Split(out, "\n")
for _, l := range imgs {
imgs := strings.SplitSeq(out, "\n")
for l := range imgs {
imgTag, imgDigest, _ := strings.Cut(l, "\t")
if strings.HasPrefix(imgTag, "test_") {
actual = append(actual, imgDigest)

View File

@@ -77,7 +77,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *
c.Setenv("PATH", testPath)
cmd := exec.Command("docker-credential-shell-test", "store")
stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": %q, "Secret": %q}`, privateRegistryURL, s.reg.Username(), s.reg.Password())))
stdin := bytes.NewReader(fmt.Appendf(nil, `{"ServerURL": "https://%s", "Username": %q, "Secret": %q}`, privateRegistryURL, s.reg.Username(), s.reg.Password()))
cmd.Stdin = stdin
assert.NilError(c, cmd.Run())

View File

@@ -217,8 +217,8 @@ func (s *DockerCLILogsSuite) TestLogsSinceFutureFollow(c *testing.T) {
since := t.Unix() + 2
out := cli.DockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name).Combined()
assert.Assert(c, out != "", "cannot read from empty log")
lines := strings.Split(strings.TrimSpace(out), "\n")
for _, v := range lines {
lines := strings.SplitSeq(strings.TrimSpace(out), "\n")
for v := range lines {
ts, err := time.Parse(time.RFC3339Nano, strings.Split(v, " ")[0])
assert.NilError(c, err, "cannot parse timestamp output from log: '%v'", v)
assert.Assert(c, ts.Unix() >= since, "earlier log found. since=%v logdate=%v", since, ts)

View File

@@ -1123,7 +1123,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c
s.d.StartWithBusybox(ctx, c)
// Run a few containers on host network
for i := 0; i < 10; i++ {
for i := range 10 {
cName := fmt.Sprintf("hostc-%d", i)
out, err := s.d.Cmd("run", "-d", "--name", cName, "--net=host", "--restart=always", "busybox", "top")
assert.NilError(c, err, out)
@@ -1138,7 +1138,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c
s.d.Start(c)
// make sure all the containers are up and running
for i := 0; i < 10; i++ {
for i := range 10 {
err := s.d.WaitRun(fmt.Sprintf("hostc-%d", i))
assert.NilError(c, err)
}

View File

@@ -104,7 +104,7 @@ func (s *DockerCLIPortSuite) TestPortList(c *testing.T) {
testRange := func() {
// host port ranges used
IDs := make([]string, 3)
for i := 0; i < 3; i++ {
for i := range 3 {
out = cli.DockerCmd(c, "run", "-d", "-p", "9090-9092:80", "busybox", "top").Stdout()
IDs[i] = strings.TrimSpace(out)
@@ -121,7 +121,7 @@ func (s *DockerCLIPortSuite) TestPortList(c *testing.T) {
// Exhausted port range did not return an error
assert.Assert(c, err != nil, "out: %s", out)
for i := 0; i < 3; i++ {
for i := range 3 {
cli.DockerCmd(c, "rm", "-f", IDs[i])
}
}
@@ -182,7 +182,7 @@ func assertPortList(t *testing.T, out string, expected []string) {
return old
}
for i := 0; i < len(expected); i++ {
for i := range expected {
if lines[i] == expected[i] {
continue
}

View File

@@ -136,7 +136,7 @@ func assertContainerList(out string, expected []string) bool {
}
containerIDIndex := strings.Index(lines[0], "CONTAINER ID")
for i := 0; i < len(expected); i++ {
for i := range expected {
foundID := lines[i+1][containerIDIndex : containerIDIndex+12]
if foundID != expected[i][:12] {
return false
@@ -531,7 +531,7 @@ func (s *DockerCLIPsSuite) TestPsListContainersFilterCreated(c *testing.T) {
out = cli.DockerCmd(c, "ps", "-a").Stdout()
hits := 0
for _, line := range strings.Split(out, "\n") {
for line := range strings.SplitSeq(out, "\n") {
if !strings.Contains(line, shortCID) {
continue
}

View File

@@ -157,7 +157,7 @@ func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *testing.T) {
// Verify that the line for 'dockercore/engine-pull-all-test-fixture:latest' is left unchanged.
var latestLine string
for _, line := range strings.Split(outImageAllTagCmd, "\n") {
for line := range strings.SplitSeq(outImageAllTagCmd, "\n") {
if strings.HasPrefix(line, "dockercore/engine-pull-all-test-fixture") && strings.Contains(line, "latest") {
latestLine = line
break

View File

@@ -79,7 +79,7 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *testing.T) {
// Ensure layer list is equivalent for repoTag1 and repoTag2
out1 := cli.DockerCmd(c, "push", repoTag1).Combined()
var out1Lines []string
for _, outputLine := range strings.Split(out1, "\n") {
for outputLine := range strings.SplitSeq(out1, "\n") {
if strings.Contains(outputLine, imageAlreadyExists) {
out1Lines = append(out1Lines, outputLine)
}
@@ -87,7 +87,7 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *testing.T) {
out2 := cli.DockerCmd(c, "push", repoTag2).Combined()
var out2Lines []string
for _, outputLine := range strings.Split(out2, "\n") {
for outputLine := range strings.SplitSeq(out2, "\n") {
if strings.Contains(outputLine, imageAlreadyExists) {
out2Lines = append(out2Lines, outputLine)
}

View File

@@ -806,7 +806,7 @@ func (s *DockerCLIRunSuite) TestRunTwoConcurrentContainers(c *testing.T) {
group.Add(2)
errChan := make(chan error, 2)
for i := 0; i < 2; i++ {
for range 2 {
go func() {
defer group.Done()
_, _, err := dockerCmdWithError("run", "busybox", "sleep", sleepTime)
@@ -2857,7 +2857,7 @@ func (s *DockerCLIRunSuite) TestRunUnshareProc(c *testing.T) {
}()
var retErr error
for i := 0; i < 3; i++ {
for range 3 {
err := <-errChan
if retErr == nil && err != nil {
retErr = err
@@ -4111,7 +4111,7 @@ func (s *DockerCLIRunSuite) TestSlowStdinClosing(c *testing.T) {
skip.If(c, testEnv.GitHubActions())
}
const repeat = 3 // regression happened 50% of the time
for i := 0; i < repeat; i++ {
for i := range repeat {
c.Run(strconv.Itoa(i), func(c *testing.T) {
cmd := icmd.Cmd{
Command: []string{dockerBinary, "run", "--rm", "-i", "busybox", "cat"},

View File

@@ -203,7 +203,7 @@ func (s *DockerSwarmSuite) TestServiceLogsFollow(c *testing.T) {
}
}()
for i := 0; i < 3; i++ {
for range 3 {
msg := <-ch
assert.NilError(c, msg.err)
assert.Assert(c, is.Contains(string(msg.data), "log test"))

View File

@@ -1486,7 +1486,7 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *testing.T) {
ctx := testutil.GetContext(c)
d := s.AddDaemon(ctx, c, true, true)
for i := 0; i < 2; i++ {
for range 2 {
// set to lock
outs, err := d.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, "out: %v", outs)
@@ -1790,7 +1790,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinLeave(c *testing.T) {
// Verify that back to back join/leave does not cause panics
d1 := s.AddDaemon(ctx, c, false, false)
for i := 0; i < 10; i++ {
for range 10 {
out, err = d1.Cmd("swarm", "join", "--token", token, d.SwarmListenAddr())
assert.NilError(c, err)
assert.Assert(c, strings.TrimSpace(out) != "")
@@ -1808,7 +1808,7 @@ func waitForEvent(t *testing.T, d *daemon.Daemon, since string, filter string, e
return ""
}
var out string
for i := 0; i < retry; i++ {
for i := range retry {
until := daemonUnixTime(t)
var err error
if filter != "" {

View File

@@ -55,8 +55,8 @@ func getContainerCount(t *testing.T) int {
result := icmd.RunCommand(dockerBinary, "info")
result.Assert(t, icmd.Success)
lines := strings.Split(result.Combined(), "\n")
for _, line := range lines {
lines := strings.SplitSeq(result.Combined(), "\n")
for line := range lines {
if strings.Contains(line, containers) {
output := strings.TrimSpace(line)
output = strings.TrimPrefix(output, containers)
@@ -435,7 +435,7 @@ func loadSpecialImage(t *testing.T, imageFunc specialimage.SpecialImageFunc) str
out := cli.DockerCmd(t, "load", "-i", imgTar).Stdout()
for _, line := range strings.Split(out, "\n") {
for line := range strings.SplitSeq(out, "\n") {
line = strings.TrimSpace(line)
if _, imageID, hasID := strings.Cut(line, "Loaded image ID: "); hasID {

View File

@@ -102,8 +102,8 @@ func (e *eventObserver) CheckEventError(t *testing.T, id, event string, match ev
if e.disconnectionError != nil {
until := daemonUnixTime(t)
out := cli.DockerCmd(t, "events", "--since", e.startTime, "--until", until).Stdout()
events := strings.Split(strings.TrimSpace(out), "\n")
for _, e := range events {
events := strings.SplitSeq(strings.TrimSpace(out), "\n")
for e := range events {
if _, ok := match(e); ok {
foundEvent = true
break
@@ -176,7 +176,7 @@ func matchEventID(matches map[string]string, id string) bool {
if !matchID && matches["attributes"] != "" {
// try matching a name in the attributes
attributes := map[string]string{}
for _, a := range strings.Split(matches["attributes"], ", ") {
for a := range strings.SplitSeq(matches["attributes"], ", ") {
kv := strings.Split(a, "=")
attributes[kv[0]] = kv[1]
}
@@ -186,8 +186,8 @@ func matchEventID(matches map[string]string, id string) bool {
}
func parseEvents(t *testing.T, out, match string) {
events := strings.Split(strings.TrimSpace(out), "\n")
for _, event := range events {
events := strings.SplitSeq(strings.TrimSpace(out), "\n")
for event := range events {
matches := eventstestutils.ScanMap(event)
matched, err := regexp.MatchString(match, matches["action"])
assert.NilError(t, err)

View File

@@ -24,7 +24,7 @@ func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {
// a map which cgroup name as key and path as value.
func ParseCgroupPaths(procCgroupData string) map[string]string {
cgroupPaths := map[string]string{}
for _, line := range strings.Split(procCgroupData, "\n") {
for line := range strings.SplitSeq(procCgroupData, "\n") {
parts := strings.Split(line, ":")
if len(parts) != 3 {
continue
@@ -120,7 +120,7 @@ func existingElements(t *testing.T, opts elementListOptions) []string {
}
out := cli.DockerCmd(t, args...).Combined()
var lines []string
for _, l := range strings.Split(out, "\n") {
for l := range strings.SplitSeq(out, "\n") {
if l != "" {
lines = append(lines, l)
}