]> Cypherpunks repositories - gostls13.git/commitdiff
net: use slices.Contains{,Func} in lookup tests
authorTobias Klauser <tklauser@distanz.ch>
Fri, 11 Oct 2024 13:47:16 +0000 (15:47 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 11 Oct 2024 22:36:26 +0000 (22:36 +0000)
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>
src/net/lookup_test.go

index d106f98eef18a9242b056e3180aa19b6b26c7669..514cbd098ae772a1628c72545fadd72b227c754b 100644 (file)
@@ -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)
                }
        }
@@ -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 {