cosmos-sdk/collections/colltest/codec_test.go
testinginprod 519630ea64
feat(collections): IndexedMap (#14397)
Co-authored-by: testinginprod <testinginprod@somewhere.idk>
Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>
2023-01-27 12:49:27 +00:00

49 lines
928 B
Go

package colltest
import "testing"
type animal interface {
name() string
}
type dog struct {
Name string `json:"name"`
BarksLoudly bool `json:"barks_loudly"`
}
type cat struct {
Name string `json:"name"`
Scratches bool `json:"scratches"`
}
func (d *cat) name() string { return d.Name }
func (d dog) name() string { return d.Name }
func TestMockValueCodec(t *testing.T) {
t.Run("primitive type", func(t *testing.T) {
x := MockValueCodec[string]()
TestValueCodec(t, x, "hello")
})
t.Run("struct type", func(t *testing.T) {
x := MockValueCodec[dog]()
TestValueCodec(t, x, dog{
Name: "kernel",
BarksLoudly: true,
})
})
t.Run("interface type", func(t *testing.T) {
x := MockValueCodec[animal]()
TestValueCodec[animal](t, x, dog{
Name: "kernel",
BarksLoudly: true,
})
TestValueCodec[animal](t, x, &cat{
Name: "echo",
Scratches: true,
})
})
}