]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/x509,embed: use slices to clean up tests
authorapocelipes <seve3r@outlook.com>
Wed, 24 Jul 2024 10:32:31 +0000 (10:32 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 24 Jul 2024 16:44:15 +0000 (16:44 +0000)
Replace reflect.DeepEqual with slices.Equal, which is much faster.

Change-Id: Ia93cc153d1f71ce92656129843be8dadcefbbca3
GitHub-Last-Rev: 0af0cc4205f51b31780ca2cbefe780e7256b1188
GitHub-Pull-Request: golang/go#67610
Reviewed-on: https://go-review.googlesource.com/c/go/+/587817
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Commit-Queue: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/crypto/x509/root_unix_test.go
src/crypto/x509/verify_test.go
src/crypto/x509/x509_test.go
src/embed/internal/embedtest/embed_test.go

index d5215b9ff2afd8c22ae99166248e202d50154dce..2ea69e252a2403f4263b690610720745d56804ed 100644 (file)
@@ -11,7 +11,7 @@ import (
        "fmt"
        "os"
        "path/filepath"
-       "reflect"
+       "slices"
        "strings"
        "testing"
 )
@@ -222,7 +222,7 @@ func TestReadUniqueDirectoryEntries(t *testing.T) {
                gotNames = append(gotNames, fi.Name())
        }
        wantNames := []string{"file", "link-out"}
-       if !reflect.DeepEqual(gotNames, wantNames) {
+       if !slices.Equal(gotNames, wantNames) {
                t.Errorf("got %q; want %q", gotNames, wantNames)
        }
 }
index ca1c744b62257000ef9625266ef0b7c2a7e37072..7f6b74b7a0f5bb1c30ae5e2e12e0435486e6eb60 100644 (file)
@@ -17,7 +17,6 @@ import (
        "internal/testenv"
        "math/big"
        "os/exec"
-       "reflect"
        "runtime"
        "slices"
        "strconv"
@@ -2595,7 +2594,7 @@ func TestPathBuilding(t *testing.T) {
                                return
                        }
                        gotChains := chainsToStrings(chains)
-                       if !reflect.DeepEqual(gotChains, tc.expectedChains) {
+                       if !slices.Equal(gotChains, tc.expectedChains) {
                                t.Errorf("unexpected chains returned:\ngot:\n\t%s\nwant:\n\t%s", strings.Join(gotChains, "\n\t"), strings.Join(tc.expectedChains, "\n\t"))
                        }
                })
index a9483b7091acc5e64a811ebe192619d309092949..351fe6ad186b14c3409cae7462732697676cbab2 100644 (file)
@@ -783,27 +783,27 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
                        t.Errorf("%s: SignatureAlgorithm wasn't copied from template. Got %v, want %v", test.name, cert.SignatureAlgorithm, test.sigAlgo)
                }
 
-               if !reflect.DeepEqual(cert.ExtKeyUsage, testExtKeyUsage) {
+               if !slices.Equal(cert.ExtKeyUsage, testExtKeyUsage) {
                        t.Errorf("%s: extkeyusage wasn't correctly copied from the template. Got %v, want %v", test.name, cert.ExtKeyUsage, testExtKeyUsage)
                }
 
-               if !reflect.DeepEqual(cert.UnknownExtKeyUsage, testUnknownExtKeyUsage) {
+               if !slices.EqualFunc(cert.UnknownExtKeyUsage, testUnknownExtKeyUsage, asn1.ObjectIdentifier.Equal) {
                        t.Errorf("%s: unknown extkeyusage wasn't correctly copied from the template. Got %v, want %v", test.name, cert.UnknownExtKeyUsage, testUnknownExtKeyUsage)
                }
 
-               if !reflect.DeepEqual(cert.OCSPServer, template.OCSPServer) {
+               if !slices.Equal(cert.OCSPServer, template.OCSPServer) {
                        t.Errorf("%s: OCSP servers differ from template. Got %v, want %v", test.name, cert.OCSPServer, template.OCSPServer)
                }
 
-               if !reflect.DeepEqual(cert.IssuingCertificateURL, template.IssuingCertificateURL) {
+               if !slices.Equal(cert.IssuingCertificateURL, template.IssuingCertificateURL) {
                        t.Errorf("%s: Issuing certificate URLs differ from template. Got %v, want %v", test.name, cert.IssuingCertificateURL, template.IssuingCertificateURL)
                }
 
-               if !reflect.DeepEqual(cert.DNSNames, template.DNSNames) {
+               if !slices.Equal(cert.DNSNames, template.DNSNames) {
                        t.Errorf("%s: SAN DNS names differ from template. Got %v, want %v", test.name, cert.DNSNames, template.DNSNames)
                }
 
-               if !reflect.DeepEqual(cert.EmailAddresses, template.EmailAddresses) {
+               if !slices.Equal(cert.EmailAddresses, template.EmailAddresses) {
                        t.Errorf("%s: SAN emails differ from template. Got %v, want %v", test.name, cert.EmailAddresses, template.EmailAddresses)
                }
 
@@ -811,11 +811,11 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
                        t.Errorf("%s: URIs differ from template. Got %v, want %v", test.name, cert.URIs, template.URIs)
                }
 
-               if !reflect.DeepEqual(cert.IPAddresses, template.IPAddresses) {
+               if !slices.EqualFunc(cert.IPAddresses, template.IPAddresses, net.IP.Equal) {
                        t.Errorf("%s: SAN IPs differ from template. Got %v, want %v", test.name, cert.IPAddresses, template.IPAddresses)
                }
 
-               if !reflect.DeepEqual(cert.CRLDistributionPoints, template.CRLDistributionPoints) {
+               if !slices.Equal(cert.CRLDistributionPoints, template.CRLDistributionPoints) {
                        t.Errorf("%s: CRL distribution points differ from template. Got %v, want %v", test.name, cert.CRLDistributionPoints, template.CRLDistributionPoints)
                }
 
@@ -2405,7 +2405,7 @@ func TestMultipleURLsInCRLDP(t *testing.T) {
                "http://epscd.catcert.net/crl/ec-acc.crl",
                "http://epscd2.catcert.net/crl/ec-acc.crl",
        }
-       if got := cert.CRLDistributionPoints; !reflect.DeepEqual(got, want) {
+       if got := cert.CRLDistributionPoints; !slices.Equal(got, want) {
                t.Errorf("CRL distribution points = %#v, want #%v", got, want)
        }
 }
@@ -3231,10 +3231,10 @@ func TestCertificateRequestRoundtripFields(t *testing.T) {
        }
        out := marshalAndParseCSR(t, in)
 
-       if !reflect.DeepEqual(in.DNSNames, out.DNSNames) {
+       if !slices.Equal(in.DNSNames, out.DNSNames) {
                t.Fatalf("Unexpected DNSNames: got %v, want %v", out.DNSNames, in.DNSNames)
        }
-       if !reflect.DeepEqual(in.EmailAddresses, out.EmailAddresses) {
+       if !slices.Equal(in.EmailAddresses, out.EmailAddresses) {
                t.Fatalf("Unexpected EmailAddresses: got %v, want %v", out.EmailAddresses, in.EmailAddresses)
        }
        if len(in.IPAddresses) != len(out.IPAddresses) ||
index a6e673a7bc2b62560f28067fba44691b38f66958..875265556f09403267319da864f4e61845ffe340 100644 (file)
@@ -8,6 +8,7 @@ import (
        "embed"
        "io"
        "reflect"
+       "slices"
        "testing"
        "testing/fstest"
 )
@@ -56,7 +57,7 @@ func testDir(t *testing.T, f embed.FS, name string, expect ...string) {
                }
                names = append(names, name)
        }
-       if !reflect.DeepEqual(names, expect) {
+       if !slices.Equal(names, expect) {
                t.Errorf("readdir %v = %v, want %v", name, names, expect)
        }
 }