github.com/cosmos/cosmos-proto@v1.0.0-beta.3/testpb/mutable_test.go (about) 1 package testpb 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 "google.golang.org/protobuf/types/dynamicpb" 8 ) 9 10 func TestMutable(t *testing.T) { 11 panics := func(f func()) (panics bool) { 12 panics = true 13 defer func() { _ = recover() }() 14 f() 15 return false 16 } 17 18 fds := md_A.Fields() 19 20 t.Run("panics", func(t *testing.T) { 21 dyn := dynamicpb.NewMessage(md_A) 22 m := &A{} 23 24 for i := 0; i < fds.Len(); i++ { 25 fd := fds.Get(i) 26 // test panic cases 27 if panics(func() { 28 dyn.Mutable(fd) 29 }) { 30 // assert fields that panic for dynamicpb panic for our implementation too 31 require.Panics(t, func() { 32 m.ProtoReflect().Mutable(fd) 33 }) 34 } else { 35 // assert fields that do not panic for dynamipb do not panic for our implementation 36 require.NotPanics(t, func() { 37 m.ProtoReflect().Mutable(fd) 38 }) 39 } 40 } 41 }) 42 }