add a function to generate sample data
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
e72cb8a0c1
commit
d8ee7baced
|
@ -51,17 +51,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) {
|
|||
func TestWriteEvent() {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
// [START populate_proto]
|
||||
e := &pb.Event{
|
||||
Id: 1234,
|
||||
Name: "jcarrEvent1",
|
||||
Email: "jcarr@wit.com",
|
||||
Results: []*pb.Event_Response{
|
||||
{Name: "foobar", Type: pb.Event_ADD},
|
||||
},
|
||||
}
|
||||
// [END populate_proto]
|
||||
|
||||
e := pb.CreateSampleEvent()
|
||||
e.Id += 1
|
||||
e.Name = "jcarrEvent2"
|
||||
|
||||
|
@ -76,14 +66,7 @@ func TestWriteEvent() {
|
|||
}
|
||||
|
||||
func marshalUnmarshal() {
|
||||
test := &pb.Event{
|
||||
Id: 1234,
|
||||
Name: "jcarrEvent1",
|
||||
Email: "jcarr@wit.com",
|
||||
Results: []*pb.Event_Response{
|
||||
{Name: "555-4321", Type: pb.Event_ADD},
|
||||
},
|
||||
}
|
||||
test := pb.CreateSampleEvent()
|
||||
data, err := proto.Marshal(test)
|
||||
if err != nil {
|
||||
log.Fatal("marshaling error: ", err)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package witProtobuf
|
||||
|
||||
import "log"
|
||||
// import "bytes"
|
||||
// import "os"
|
||||
// import "bufio"
|
||||
// import "io"
|
||||
// import "io/ioutil"
|
||||
|
||||
func CreateSampleEvent() *Event {
|
||||
// TODO: flush this out to do all the fields
|
||||
log.Println("CreateSampleEvent() is generating a example protobuf Event")
|
||||
|
||||
e := &Event{
|
||||
Id: 1234,
|
||||
Name: "jcarrEvent1",
|
||||
Email: "jcarr@wit.com",
|
||||
Results: []*Event_Response{
|
||||
{Name: "foobar", Type: Event_ADD},
|
||||
},
|
||||
}
|
||||
|
||||
e.Id += 1
|
||||
e.Name = "jcarrEvent2"
|
||||
|
||||
return e
|
||||
}
|
Loading…
Reference in New Issue