github.com/cosmos/cosmos-proto@v1.0.0-beta.3/rapidproto/rapidproto_test.go (about) 1 package rapidproto_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "google.golang.org/protobuf/encoding/protojson" 8 "google.golang.org/protobuf/proto" 9 "gotest.tools/v3/assert" 10 "gotest.tools/v3/golden" 11 "pgregory.net/rapid" 12 13 "github.com/cosmos/cosmos-proto/rapidproto" 14 "github.com/cosmos/cosmos-proto/testpb" 15 ) 16 17 // TestRegression checks that the generator still produces the same output 18 // for the same random seeds, assuming that this data has been hand expected 19 // to generally look good. 20 func TestRegression(t *testing.T) { 21 gen := rapidproto.MessageGenerator(&testpb.A{}, rapidproto.GeneratorOptions{}) 22 for i := 1000; i < 1005; i++ { 23 testRegressionSeed(t, i, gen) 24 } 25 } 26 27 func testRegressionSeed[X proto.Message](t *testing.T, seed int, generator *rapid.Generator[X]) { 28 x := generator.Example(seed) 29 bz, err := protojson.Marshal(x) 30 assert.NilError(t, err) 31 golden.Assert(t, string(bz), fmt.Sprintf("seed%d.json", seed)) 32 }