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

@@ -861,7 +861,7 @@ type buildLine struct {
func getImageIDsFromBuild(output []byte) ([]string, error) {
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

@@ -893,7 +893,7 @@ func TestFirewallBackendSwitch(t *testing.T) {
})
// TODO: (When Go 1.24 is min version) Replace with `strings.Lines(dump)`.
for _, line := range strings.Split(dump, "\n") {
for line := range strings.SplitSeq(dump, "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue

View File

@@ -1593,7 +1593,7 @@ func checkProxies(ctx context.Context, t *testing.T, c *client.Client, daemonPid
t.Error(res)
return
}
for _, line := range strings.Split(res.Stdout(), "\n") {
for line := range strings.SplitSeq(res.Stdout(), "\n") {
_, args, ok := strings.Cut(line, "docker-proxy")
if !ok {
continue
@@ -1787,7 +1787,7 @@ func TestAdvertiseAddresses(t *testing.T) {
// the associated MAC address.
findNeighMAC := func(neighOut, ip string) string {
t.Helper()
for _, line := range strings.Split(neighOut, "\n") {
for line := range strings.SplitSeq(neighOut, "\n") {
// Lines look like ...
// 172.22.22.22 dev eth0 lladdr 36:bc:ce:67:f3:e4 ref 1 used 0/7/0 probes 1 DELAY
fields := strings.Fields(line)
@@ -2017,7 +2017,7 @@ func TestLegacyLinksEnvVars(t *testing.T) {
// Check the list of environment variables set in the linking container.
var found bool
for _, l := range strings.Split(exportRes.Stdout.String(), "\n") {
for l := range strings.SplitSeq(exportRes.Stdout.String(), "\n") {
if strings.HasPrefix(l, "export CTR1_") {
// Legacy links env var found, but not expected.
if !tc.expectEnvVars {

View File

@@ -281,8 +281,8 @@ func enableIPv6OnAll(t *testing.T) func() {
ifaces := map[string]string{}
var allVal string
sysctls := strings.Split(string(out), "\n")
for _, sysctl := range sysctls {
sysctls := strings.SplitSeq(string(out), "\n")
for sysctl := range sysctls {
if sysctl == "" {
continue
}
@@ -1470,7 +1470,7 @@ func TestAccessPortPublishedOnLoopbackAddress(t *testing.T) {
func sendPayloadFromHost(t *testing.T, host networking.Host, daddr, dport, payload string, check func() bool) bool {
var res bool
host.Do(t, func() {
for i := 0; i < 10; i++ {
for i := range 10 {
t.Logf("Sending probe #%d to %s:%s from host %s", i, daddr, dport, host.Name)
icmd.RunCommand("/bin/sh", "-c", fmt.Sprintf("echo '%s' | nc -w1 -u %s %s", payload, daddr, dport)).Assert(t, icmd.Success)

View File

@@ -59,7 +59,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
go func() {
defer close(chErr)
rdr := bufio.NewReader(attach.Reader)
for i := 0; i < 5; i++ {
for range 5 {
_, _, err := rdr.ReadLine()
if err != nil {
chErr <- err

View File

@@ -121,7 +121,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
// a few times, to give tasks time to be deallocated
poll.WaitOn(t, swarm.NoTasksForService(ctx, apiClient, serviceID2), swarm.ServicePoll)
for retry := 0; retry < 5; retry++ {
for range 5 {
_, err = apiClient.NetworkRemove(ctx, overlayID, client.NetworkRemoveOptions{})
// TODO(dperny): using strings.Contains for error checking is awful,
// but so is the fact that swarm functions don't return errdefs errors.

View File

@@ -37,7 +37,7 @@ func TestServiceListWithStatuses(t *testing.T) {
serviceCount := 3
// create some services.
for i := 0; i < serviceCount; i++ {
for i := range serviceCount {
spec := fullSwarmServiceSpec(fmt.Sprintf("test-list-%d", i), uint64(i+1))
// for whatever reason, the args "-u root", when included, cause these
// tasks to fail and exit. instead, we'll just pass no args, which