Skip to content

Commit

Permalink
test: fix racy tests
Browse files Browse the repository at this point in the history
update tests to no longer share the same message instance
  • Loading branch information
Dylan Bourque authored and dylan-bourque committed Jun 12, 2024
1 parent 6fd2269 commit 5bbcf97
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion example/proto2_googlev1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

func TestProto2GoogleV1Message(t *testing.T) {
msg := createTestProto2GoogleV1Message()
t.Run("google_marshal/csproto_unmarshal", func(t *testing.T) {
msg := createTestProto2GoogleV1Message()
data, err := proto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using golang/protobuf: %v", err)
Expand All @@ -33,6 +33,7 @@ func TestProto2GoogleV1Message(t *testing.T) {
}
})
t.Run("csproto_marshal/google_unmarshal", func(t *testing.T) {
msg := createTestProto2GoogleV1Message()
data, err := csproto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using csproto: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion example/proto2_googlev2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

func TestProto2GoogleV2Message(t *testing.T) {
msg := createTestProto2GoogleV2Message()
t.Run("google_marshal/csproto_unmarshal", func(t *testing.T) {
msg := createTestProto2GoogleV2Message()
data, err := proto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using golang/protobuf: %v", err)
Expand All @@ -33,6 +33,7 @@ func TestProto2GoogleV2Message(t *testing.T) {
}
})
t.Run("csproto_marshal/google_unmarshal", func(t *testing.T) {
msg := createTestProto2GoogleV2Message()
data, err := csproto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using csproto: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions example/proto3_googlev1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
)

func TestProto3GoogleV1Message(t *testing.T) {
msg := createTestProto3GoogleV1Message()

t.Run("google_marshal/csproto_unmarshal", func(t *testing.T) {
msg := createTestProto3GoogleV1Message()
data, err := proto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using golang/protobuf: %v", err)
Expand All @@ -33,6 +32,7 @@ func TestProto3GoogleV1Message(t *testing.T) {
}
})
t.Run("csproto_marshal/google_unmarshal", func(t *testing.T) {
msg := createTestProto3GoogleV1Message()
data, err := csproto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using csproto: %v", err)
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestProto3GoogleV1Equal(t *testing.T) {
// m1 and m2 will have different timestamps so should not be equal
assert.False(t, csproto.Equal(m1, m2), "messages should not be equal\nm1=%s\nm2=%s", m1.String(), m2.String())
// make them equal
*m2.Ts = *m1.Ts
m2.Ts, _ = csproto.Clone(m1.Ts).(*timestamppb.Timestamp)
assert.True(t, csproto.Equal(m1, m2), "messages should be equal\nm1=%s\nm2=%s", m1.String(), m2.String())
}

Expand Down
6 changes: 3 additions & 3 deletions example/proto3_googlev2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
)

func TestProto3GoogleV2Message(t *testing.T) {
msg := createTestProto3GoogleV2Message()

t.Run("google_marshal/csproto_unmarshal", func(t *testing.T) {
msg := createTestProto3GoogleV2Message()
data, err := proto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using golang/protobuf: %v", err)
Expand All @@ -38,6 +37,7 @@ func TestProto3GoogleV2Message(t *testing.T) {
}
})
t.Run("csproto_marshal/google_unmarshal", func(t *testing.T) {
msg := createTestProto3GoogleV2Message()
data, err := csproto.Marshal(msg)
if err != nil {
t.Errorf("Error marshaling data using csproto: %v", err)
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestProto3GoogleV2Equal(t *testing.T) {
// m1 and m2 will have different timestamps so should not be equal
assert.False(t, csproto.Equal(m1, m2), "messages should not be equal\nm1=%s\nm2=%s", m1.String(), m2.String())
// make them equal
*m2.Ts = *m1.Ts
m2.Ts, _ = csproto.Clone(m1.Ts).(*timestamppb.Timestamp)
assert.True(t, csproto.Equal(m1, m2), "messages should be equal\nm1=%s\nm2=%s", m1.String(), m2.String())
}

Expand Down

0 comments on commit 5bbcf97

Please sign in to comment.