mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
Replace uses of code which requires 1.24+
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
@@ -889,7 +889,9 @@ func TestFirewallBackendSwitch(t *testing.T) {
|
||||
dump = icmd.RunCommand("iptables-save").Combined()
|
||||
dump += icmd.RunCommand("ip6tables-save").Combined()
|
||||
})
|
||||
for line := range strings.Lines(dump) {
|
||||
|
||||
// TODO: (When Go 1.24 is min version) Replace with `strings.Lines(dump)`.
|
||||
for _, line := range strings.Split(dump, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
|
||||
@@ -20,6 +20,7 @@ package nftablesdoc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"iter"
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -413,7 +414,7 @@ func runNftables(t *testing.T, host networking.Host) map[string]string {
|
||||
// {{index . "map filter-forward-out-jumps"}}
|
||||
|
||||
var sb strings.Builder
|
||||
for line := range strings.Lines(out) {
|
||||
for line := range lines(out) {
|
||||
if line == "\n" || (line != "" && line[0] == '}') {
|
||||
block := sb.String()
|
||||
sb.Reset()
|
||||
@@ -428,6 +429,24 @@ func runNftables(t *testing.T, host networking.Host) map[string]string {
|
||||
return res
|
||||
}
|
||||
|
||||
// lines produces a line iterator
|
||||
// TODO: (When Go 1.24 is min version) Replace with `strings.Lines(out)`.
|
||||
func lines(s string) iter.Seq[string] {
|
||||
return func(yield func(string) bool) {
|
||||
for s != "" {
|
||||
var line string
|
||||
if i := strings.IndexByte(s, '\n'); i >= 0 {
|
||||
line, s = s[:i+1], s[i+1:]
|
||||
} else {
|
||||
line, s = s, ""
|
||||
}
|
||||
if !yield(line) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func generate(t *testing.T, name string, data map[string]string) string {
|
||||
t.Helper()
|
||||
templ, err := template.New(name).ParseFiles(filepath.Join("templates", name))
|
||||
|
||||
Reference in New Issue
Block a user