Skip to content

Commit 1beb968

Browse files
committed
Fix reflect comparisons due to sync.Map changes
There's a new sync.Map implementation controllable via GOEXPERIMENT value. In the test use cases, we likely don't care about the strict reflect equality so we can swap to an alternative comparison implementation. Other uses of reflect.DeepEqual(...) at runtime don't appear to operate over sync.Map instances and so aren't affected. See also: https://tip.golang.org/doc/go1.24#syncpkgsync See also: golang/go#71702 Signed-off-by: Alexander Scheel <[email protected]>
1 parent e894fae commit 1beb968

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

vault/auth_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ package vault
55

66
import (
77
"context"
8-
"reflect"
98
"strings"
109
"testing"
1110
"time"
1211

13-
"github.com/openbao/openbao/helper/testhelpers/corehelpers"
14-
1512
"github.com/armon/go-metrics"
13+
"github.com/go-test/deep"
14+
1615
"github.com/openbao/openbao/helper/metricsutil"
1716
"github.com/openbao/openbao/helper/namespace"
17+
"github.com/openbao/openbao/helper/testhelpers/corehelpers"
1818
"github.com/openbao/openbao/helper/versions"
1919
"github.com/openbao/openbao/sdk/v2/helper/consts"
2020
"github.com/openbao/openbao/sdk/v2/helper/jsonutil"
@@ -142,8 +142,8 @@ func TestCore_DefaultAuthTable(t *testing.T) {
142142
}
143143

144144
// Verify matching mount tables
145-
if !reflect.DeepEqual(c.auth, c2.auth) {
146-
t.Fatalf("mismatch: %v %v", c.auth, c2.auth)
145+
if diff := deep.Equal(c.auth, c2.auth); diff != nil {
146+
t.Fatalf("mismatch:\n\tc.auth: %#v\n\tc2.auth: %#v\n\tdiff: %#v", c.auth, c2.auth, diff)
147147
}
148148
}
149149

@@ -238,8 +238,8 @@ func TestCore_EnableCredential(t *testing.T) {
238238
c2Auth[entry.UUID] = entry
239239
}
240240

241-
if !reflect.DeepEqual(cAuth, c2Auth) {
242-
t.Fatalf("mismatch: %#v %#v", cAuth, c2Auth)
241+
if diff := deep.Equal(cAuth, c2Auth); diff != nil {
242+
t.Fatalf("mismatch:\n\tcAuth: %#v\n\tc2Auth: %#v\n\tDiff: %#v", cAuth, c2Auth, diff)
243243
}
244244
}
245245

@@ -306,8 +306,8 @@ func TestCore_EnableCredential_aws_ec2(t *testing.T) {
306306
c2Auth[entry.UUID] = entry
307307
}
308308

309-
if !reflect.DeepEqual(cAuth, c2Auth) {
310-
t.Fatalf("mismatch: %#v %#v", cAuth, c2Auth)
309+
if diff := deep.Equal(cAuth, c2Auth); diff != nil {
310+
t.Fatalf("mismatch:\n\tcAuth: %#v\n\tc2Auth: %#v\n\tdiff: %#v", cAuth, c2Auth, diff)
311311
}
312312
}
313313

@@ -400,8 +400,8 @@ func TestCore_EnableCredential_Local(t *testing.T) {
400400
t.Fatal(err)
401401
}
402402

403-
if !reflect.DeepEqual(oldCredential, c.auth) {
404-
t.Fatalf("expected\n%#v\ngot\n%#v\n", oldCredential, c.auth)
403+
if diff := deep.Equal(oldCredential, c.auth); diff != nil {
404+
t.Fatalf("expected\n%#v\ngot\n%#v\ndiff: %#v\n", oldCredential, c.auth, diff)
405405
}
406406

407407
if len(c.auth.Entries) != 2 {
@@ -508,8 +508,8 @@ func TestCore_DisableCredential(t *testing.T) {
508508
}
509509

510510
// Verify matching mount tables
511-
if !reflect.DeepEqual(c.auth, c2.auth) {
512-
t.Fatalf("mismatch: %v %v", c.auth, c2.auth)
511+
if diff := deep.Equal(c.auth, c2.auth); diff != nil {
512+
t.Fatalf("mismatch:\n\tc.auth: %v\n\tc2.auth: %v\n\tdiff: %#v", c.auth, c2.auth, diff)
513513
}
514514
}
515515

vault/mount_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ func TestCore_Mount_Local(t *testing.T) {
376376
}
377377
c.mounts.Entries = compEntries
378378

379-
if !reflect.DeepEqual(oldMounts, c.mounts) {
380-
t.Fatalf("expected\n%#v\ngot\n%#v\n", oldMounts, c.mounts)
379+
if diff := deep.Equal(oldMounts, c.mounts); diff != nil {
380+
t.Fatalf("expected\n%#v\ngot\n%#v\ndiff: %#v\n", oldMounts, c.mounts, diff)
381381
}
382382

383383
if len(c.mounts.Entries) != 2 {

0 commit comments

Comments
 (0)