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>
This commit is contained in:
co-authored by
testinginprod
Marko
Likhita Polavarapu
parent
ed17f2d437
commit
519630ea64
@@ -0,0 +1,48 @@
|
||||
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,
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user