Skip to content

Commit

Permalink
net: do not modify shared test variable in TestDNSReadConfig
Browse files Browse the repository at this point in the history
Fixes golang#56542

Change-Id: I294856f8fb4d49393310ec92ab40fb7d841b6570
GitHub-Last-Rev: a456340
GitHub-Pull-Request: golang#56545
Reviewed-on: https://go-review.googlesource.com/c/go/+/447198
Reviewed-by: Bryan Mills <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
mateusz834 authored and romaindoumenc committed Nov 3, 2022
1 parent 9a7acab commit a9074ab
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/net/dnsconfig_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,17 @@ func TestDNSReadConfig(t *testing.T) {
getHostname = func() (string, error) { return "host.domain.local", nil }

for _, tt := range dnsReadConfigTests {
if len(tt.want.search) == 0 {
tt.want.search = append(tt.want.search, dnsDefaultSearch()...)
want := *tt.want
if len(want.search) == 0 {
want.search = dnsDefaultSearch()
}
conf := dnsReadConfig(tt.name)
if conf.err != nil {
t.Fatal(conf.err)
}
conf.mtime = time.Time{}
if !reflect.DeepEqual(conf, tt.want) {
t.Errorf("%s:\ngot: %+v\nwant: %+v", tt.name, conf, tt.want)
if !reflect.DeepEqual(conf, &want) {
t.Errorf("%s:\ngot: %+v\nwant: %+v", tt.name, conf, want)
}
}
}
Expand Down Expand Up @@ -272,8 +273,13 @@ func TestDNSNameLength(t *testing.T) {
t.Fatal(conf.err)
}

suffixList := tt.want.search
if len(suffixList) == 0 {
suffixList = dnsDefaultSearch()
}

var shortestSuffix int
for _, suffix := range tt.want.search {
for _, suffix := range suffixList {
if shortestSuffix == 0 || len(suffix) < shortestSuffix {
shortestSuffix = len(suffix)
}
Expand Down

0 comments on commit a9074ab

Please sign in to comment.