Skip to content

Commit

Permalink
*: Compare protojson's using require.JSONEq in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
  • Loading branch information
cthulhu-rider committed Sep 30, 2024
1 parent 0246d63 commit 4303331
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
10 changes: 3 additions & 7 deletions bearer/bearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,15 +827,11 @@ func TestToken_Unmarshal(t *testing.T) {
}

func TestToken_MarshalJSON(t *testing.T) {
//nolint:staticcheck
b, err := json.MarshalIndent(validBearerToken, "", " ")
require.NoError(t, err)
if string(b) != validJSONBearerToken {
// protojson is inconsistent https://github.com/golang/protobuf/issues/1121
var val bearer.Token
require.NoError(t, val.UnmarshalJSON(b))
t.Skip("https://github.com/nspcc-dev/neofs-sdk-go/issues/606")
require.Equal(t, validBearerToken, val)
}
t.Skip("https://github.com/nspcc-dev/neofs-sdk-go/issues/606")
require.JSONEq(t, validJSONBearerToken, string(b))
}

func TestToken_UnmarshalJSON(t *testing.T) {
Expand Down
10 changes: 3 additions & 7 deletions session/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,11 @@ func TestContainer_Unmarshal(t *testing.T) {

func TestContainer_MarshalJSON(t *testing.T) {
for i := range validContainerTokens {
//nolint:staticcheck
b, err := json.MarshalIndent(validContainerTokens[i], "", " ")
require.NoError(t, err, i)
if string(b) != validJSONContainerTokens[i] {
// protojson is inconsistent https://github.com/golang/protobuf/issues/1121
var val session.Container
require.NoError(t, val.UnmarshalJSON(b), i)
t.Skip("https://github.com/nspcc-dev/neofs-sdk-go/issues/606")
require.Equal(t, validContainerTokens[i], val, i)
}
t.Skip("https://github.com/nspcc-dev/neofs-sdk-go/issues/606")
require.JSONEq(t, validJSONContainerTokens[i], string(b))
}
}

Expand Down
10 changes: 3 additions & 7 deletions session/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,11 @@ func TestObject_Unmarshal(t *testing.T) {
}

func TestObject_MarshalJSON(t *testing.T) {
//nolint:staticcheck
b, err := json.MarshalIndent(validObjectToken, "", " ")
require.NoError(t, err)
if string(b) != validJSONObjectToken {
// protojson is inconsistent https://github.com/golang/protobuf/issues/1121
var val session.Object
require.NoError(t, val.UnmarshalJSON(b))
t.Skip("https://github.com/nspcc-dev/neofs-sdk-go/issues/606")
require.Equal(t, validObjectToken, val)
}
t.Skip("https://github.com/nspcc-dev/neofs-sdk-go/issues/606")
require.JSONEq(t, validJSONObjectToken, string(b))
}

func TestObject_UnmarshalJSON(t *testing.T) {
Expand Down
7 changes: 1 addition & 6 deletions version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ func TestVersion_String(t *testing.T) {
func TestVersion_MarshalJSON(t *testing.T) {
b, err := validVersion.MarshalJSON()
require.NoError(t, err)
if string(b) != validJSON {
// protojson is inconsistent https://github.com/golang/protobuf/issues/1121
var v version.Version
require.NoError(t, v.UnmarshalJSON(b))
require.Equal(t, validVersion, v)
}
require.JSONEq(t, validJSON, string(b))
}

func TestVersion_UnmarshalJSON(t *testing.T) {
Expand Down

0 comments on commit 4303331

Please sign in to comment.