You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
757 B

  1. package client
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. )
  7. type Tx []byte
  8. type Foo struct {
  9. Bar int
  10. Baz string
  11. }
  12. func TestArgToJSON(t *testing.T) {
  13. assert := assert.New(t)
  14. require := require.New(t)
  15. cases := []struct {
  16. input interface{}
  17. expected string
  18. }{
  19. {[]byte("1234"), "0x31323334"},
  20. {Tx("654"), "0x363534"},
  21. {Foo{7, "hello"}, `{"Bar":"7","Baz":"hello"}`},
  22. }
  23. for i, tc := range cases {
  24. args := map[string]interface{}{"data": tc.input}
  25. err := argsToJSON(args)
  26. require.Nil(err, "%d: %+v", i, err)
  27. require.Equal(1, len(args), "%d", i)
  28. data, ok := args["data"].(string)
  29. require.True(ok, "%d: %#v", i, args["data"])
  30. assert.Equal(tc.expected, data, "%d", i)
  31. }
  32. }