Skip to content

Commit

Permalink
net: use slices.Contains{,Func} in lookup tests
Browse files Browse the repository at this point in the history
Change-Id: I66199995ca34c92aeb8234b43cb2166f2976c903
Reviewed-on: https://go-review.googlesource.com/c/go/+/619735
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
  • Loading branch information
tklauser authored and gopherbot committed Oct 11, 2024
1 parent 86a1a99 commit 7e0159c
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/net/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,10 @@ func TestLookupGmailTXT(t *testing.T) {
if len(txts) == 0 {
t.Error("got no record")
}
found := false
for _, txt := range txts {
if strings.Contains(txt, tt.txt) && (strings.HasSuffix(txt, tt.host) || strings.HasSuffix(txt, tt.host+".")) {
found = true
break
}
}
if !found {

if !slices.ContainsFunc(txts, func(txt string) bool {
return strings.Contains(txt, tt.txt) && (strings.HasSuffix(txt, tt.host) || strings.HasSuffix(txt, tt.host+"."))
}) {
t.Errorf("got %v; want a record containing %s, %s", txts, tt.txt, tt.host)
}
}
Expand Down Expand Up @@ -302,14 +298,7 @@ func TestLookupIPv6LinkLocalAddr(t *testing.T) {
if err != nil {
t.Fatal(err)
}
found := false
for _, addr := range addrs {
if addr == "fe80::1%lo0" {
found = true
break
}
}
if !found {
if !slices.Contains(addrs, "fe80::1%lo0") {
t.Skipf("not supported on %s", runtime.GOOS)
}
if _, err := LookupAddr("fe80::1%lo0"); err != nil {
Expand Down

0 comments on commit 7e0159c

Please sign in to comment.