Documentation ¶
Overview ¶
Package pbtest provides mechanisms to assist with testing of Protocol Buffer messages.
Example ¶
package main import ( "testing" "testing/quick" "github.com/golang/protobuf/proto" ) func main() { // You would place this in a top-level function, like TestDatastore(t *testing.T). var ( datastore Datastore t *testing.T ) if err := quick.Check(func(rec *CustomerRecord) bool { // testing/quick generated rec using quick.Value. We want to ensure that // semi-internal struct fields are recursively reset to a known value. SanitizeGenerated(rec) // Ensure that any record can be stored, no matter what! if err := datastore.Store(rec); err != nil { return false } return true }, nil); err != nil { t.Fatal(err) } } // Datastore models some system under test. type Datastore struct{} // Store stores a customer record. func (Datastore) Store(*CustomerRecord) error { return nil } // Types below are generated from protoc --go_out=. example.proto, where // example.proto contains // """ // syntax = "proto2"; // message CustomerRecord { // } // """ type CustomerRecord struct { XXX_unrecognized []byte `json:"-"` } func (m *CustomerRecord) Reset() { *m = CustomerRecord{} } func (m *CustomerRecord) String() string { return proto.CompactTextString(m) } func (*CustomerRecord) ProtoMessage() {}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SanitizeGenerated ¶
SanitizeGenerated empties the private state fields of Protocol Buffer messages that have been generated by the testing/quick package or returns an error indicating a problem it encountered.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.