diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index c12451f..7fb58ce 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -20,7 +20,11 @@ }, { "ImportPath": "github.com/matttproud/golang_protobuf_extensions/ext", - "Rev": "ba7d65ac66e9da93a714ca18f6d1bc7a0c09100c" + "Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a" + }, + { + "ImportPath": "github.com/matttproud/golang_protobuf_extensions/pbutil", + "Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a" }, { "ImportPath": "github.com/prometheus/client_model/go", diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/all_test.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/all_test.go similarity index 87% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/all_test.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/all_test.go index 7270b67..094156e 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/all_test.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/all_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ext +package pbutil import ( "bytes" @@ -21,6 +21,8 @@ import ( "testing" "testing/quick" + "github.com/matttproud/golang_protobuf_extensions/pbtest" + . "github.com/golang/protobuf/proto" . "github.com/golang/protobuf/proto/testdata" ) @@ -138,10 +140,10 @@ I expect it may. Let's hope you enjoy testing as much as we do.`), func TestEndToEndValid(t *testing.T) { for _, test := range [][]Message{ - []Message{&Empty{}}, - []Message{&GoEnum{Foo: FOO_FOO1.Enum()}, &Empty{}, &GoEnum{Foo: FOO_FOO1.Enum()}}, - []Message{&GoEnum{Foo: FOO_FOO1.Enum()}}, - []Message{&Strings{ + {&Empty{}}, + {&GoEnum{Foo: FOO_FOO1.Enum()}, &Empty{}, &GoEnum{Foo: FOO_FOO1.Enum()}}, + {&GoEnum{Foo: FOO_FOO1.Enum()}}, + {&Strings{ StringField: String(`This is my gigantic, unhappy string. It exceeds the encoding size of a single byte varint. We are using it to fuzz test the correctness of the header decoding mechanisms, which may prove problematic. @@ -176,45 +178,6 @@ I expect it may. Let's hope you enjoy testing as much as we do.`), } } -// visitMessage empties the private state fields of the quick.Value()-generated -// Protocol Buffer messages, for they cause an inordinate amount of problems. -// This is because we are using an automated fuzz generator on a type with -// private fields. -func visitMessage(m Message) { - t := reflect.TypeOf(m) - if t.Kind() != reflect.Ptr { - return - } - derefed := t.Elem() - if derefed.Kind() != reflect.Struct { - return - } - v := reflect.ValueOf(m) - elem := v.Elem() - for i := 0; i < elem.NumField(); i++ { - field := elem.FieldByIndex([]int{i}) - fieldType := field.Type() - if fieldType.Implements(reflect.TypeOf((*Message)(nil)).Elem()) { - visitMessage(field.Interface().(Message)) - } - if field.Kind() == reflect.Slice { - for i := 0; i < field.Len(); i++ { - elem := field.Index(i) - elemType := elem.Type() - if elemType.Implements(reflect.TypeOf((*Message)(nil)).Elem()) { - visitMessage(elem.Interface().(Message)) - } - } - } - } - if field := elem.FieldByName("XXX_unrecognized"); field.IsValid() { - field.Set(reflect.ValueOf([]byte{})) - } - if field := elem.FieldByName("XXX_extensions"); field.IsValid() { - field.Set(reflect.ValueOf(nil)) - } -} - // rndMessage generates a random valid Protocol Buffer message. func rndMessage(r *rand.Rand) Message { var t reflect.Type @@ -307,7 +270,9 @@ func rndMessage(r *rand.Rand) Message { if !ok { panic("attempt to generate illegal item; consult item 11") } - visitMessage(v.Interface().(Message)) + if err := pbtest.SanitizeGenerated(v.Interface().(Message)); err != nil { + panic(err) + } return v.Interface().(Message) } diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/decode.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go similarity index 99% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/decode.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go index 28b520e..66d9b54 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/decode.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ext +package pbutil import ( "encoding/binary" diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/doc.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go similarity index 86% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/doc.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go index 652907b..c318385 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/doc.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go @@ -12,5 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package ext enables record length-delimited Protocol Buffer streaming. -package ext +// Package pbutil provides record length-delimited Protocol Buffer streaming. +package pbutil diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/encode.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go similarity index 99% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/encode.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go index 473b31d..4b76ea9 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/encode.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ext +package pbutil import ( "encoding/binary" diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/fixtures_test.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go similarity index 99% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/fixtures_test.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go index 07e75c5..d6d9b25 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/fixtures_test.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go @@ -27,7 +27,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package ext +package pbutil import ( . "github.com/golang/protobuf/proto"