Files
ARTEX/cmd/artex-runner/main_test.go
AmirGhasemi c7b52f297f fix(runner): review feedback — unicode.IsSpace split, Dns only on proxy, parser test
- parseDNSList: split on comma or any unicode.IsSpace rune so tabs and
  newlines in ARTEX_TASK_DNS act as separators, not address bytes.
- proxySpec: add HostConfig.Dns only when the list is non-empty so the
  serialized spec is byte-identical when ARTEX_TASK_DNS is unset.
- workerSpec: drop Dns entirely — the worker sits on the --internal
  task network and resolves through the egress proxy; setting Dns there
  would relay worker DNS around the proxy.
- add cmd/artex-runner/main_test.go: TestParseDNSList covers valid
  comma/space/mixed/newline-separated lists, IPv6, empty and
  separator-only input, invalid entries dropped (with valid kept),
  hostnames dropped, and asserts every output entry parses as an IP.
2026-12-03 14:01:54 +01:00

82 lines
1.9 KiB
Go

package main
import (
"net"
"reflect"
"testing"
)
func TestParseDNSList(t *testing.T) {
cases := []struct {
name string
input string
want []string
}{
{
name: "comma separated",
input: "10.21.232.232,10.22.232.232,1.1.1.1",
want: []string{"10.21.232.232", "10.22.232.232", "1.1.1.1"},
},
{
name: "space separated",
input: "10.21.232.232 10.22.232.232",
want: []string{"10.21.232.232", "10.22.232.232"},
},
{
name: "mixed separators with surrounding whitespace",
input: " 10.21.232.232 , 10.22.232.232\t1.1.1.1 ",
want: []string{"10.21.232.232", "10.22.232.232", "1.1.1.1"},
},
{
name: "newline separated",
input: "10.21.232.232\n10.22.232.232\n",
want: []string{"10.21.232.232", "10.22.232.232"},
},
{
name: "ipv6 addresses",
input: "2001:db8::1,fd00::53",
want: []string{"2001:db8::1", "fd00::53"},
},
{
name: "empty input",
input: "",
want: nil,
},
{
name: "only separators and whitespace",
input: " , \t\n ,, ",
want: nil,
},
{
name: "invalid entries dropped with valid kept",
input: "10.21.232.232,not-an-ip,10.22.232.232",
want: []string{"10.21.232.232", "10.22.232.232"},
},
{
name: "hostnames are not addresses and are dropped",
input: "dns.corp.example,10.21.232.232",
want: []string{"10.21.232.232"},
},
{
name: "all invalid",
input: "nope,,still-nope",
want: nil,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := parseDNSList(tc.input)
if !reflect.DeepEqual(got, tc.want) {
t.Fatalf("parseDNSList(%q) = %v, want %v", tc.input, got, tc.want)
}
// Every returned entry must be a parseable IP (the contract the
// Docker daemon will enforce on HostConfig.Dns).
for _, e := range got {
if net.ParseIP(e) == nil {
t.Fatalf("parseDNSList(%q) returned non-IP entry %q", tc.input, e)
}
}
})
}
}