Skip to content

Commit

Permalink
chore: encoding unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed Oct 14, 2023
1 parent f3c7a78 commit f6c0de1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions testutil/encoding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package testutil_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"

"github.com/Finschia/finschia-sdk/testutil"
)

func TestMustJSONMarshal(t *testing.T) {
type tc struct {
Name string `json:"myName"`
Order string `json:"myOrder"`
}

a := tc{
Name: "test",
Order: "first",
}
b := new(tc)

marshaled := testutil.MustJSONMarshal(a)
err := json.Unmarshal(marshaled, b)
require.NoError(t, err)
require.Equal(t, a, *b)
require.Panics(t, func() { testutil.MustJSONMarshal(make(chan int)) })
}

func TestW(t *testing.T) {
require.Equal(t, []byte(`"test"`), testutil.W("test"))
}

0 comments on commit f6c0de1

Please sign in to comment.