pbtest

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2016 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 0

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

func SanitizeGenerated(m proto.Message) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL