diff --git a/configfile/main.go b/configfile/main.go index 727559d..bbd2c70 100644 --- a/configfile/main.go +++ b/configfile/main.go @@ -32,8 +32,8 @@ func main() { } } -func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Cluster) { - buf, err := proto.Marshal(e) +func marshalWriteToFile(myWriter *bufio.Writer, c *pb.Cluster) { + buf, err := proto.Marshal(c) if err != nil { log.Fatal("marshaling error: ", err) } @@ -41,7 +41,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Cluster) { myWriter.Flush() log.Println("bufio.Write() tmp, err = ", tmp, err) - buf, err = proto.Marshal(e) + buf, err = proto.Marshal(c) tmp2, err := myWriter.Write(buf) myWriter.Flush() log.Println("bufio.Write() tmp2, err = ", tmp2, err) @@ -50,26 +50,26 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Cluster) { func TestWriteDroplet() { buf := new(bytes.Buffer) - e := pb.CreateSampleCluster(10) + c := pb.CreateSampleCluster(3) got := buf.String() log.Println(got) newfile, _ := os.Create("/tmp/testing4.protobuf") myWriter := bufio.NewWriter(newfile) - marshalWriteToFile(myWriter, e) + marshalWriteToFile(myWriter, c) marshalUnmarshal() } func marshalUnmarshal() { - test := pb.CreateSampleCluster(10) + test := pb.CreateSampleCluster(7) data, err := proto.Marshal(test) if err != nil { log.Fatal("marshaling error: ", err) } - newTest := &pb.Droplet{} + newTest := &pb.Cluster{} err = proto.Unmarshal(data, newTest) if err != nil { log.Fatal("unmarshaling error: ", err) diff --git a/sampleData.go b/sampleData.go index c910200..7f64b96 100644 --- a/sampleData.go +++ b/sampleData.go @@ -1,21 +1,24 @@ package virtbuf -import "log" +import ( + "fmt" + "log" +) // // This generates some sample data. It *should* match the .proto file // -func CreateSampleDroplet() *Droplet { +func CreateSampleDroplet(hostname string) *Droplet { // TODO: flush this out to do all the fields - log.Println("CreateSampleDroplet() is generating a new droplet") + log.Println("CreateSampleDroplet() is generating a new droplet", hostname) - e := &Droplet{ + d := &Droplet{ Uuid: "6a1c571b-1d02-462b-9288-63d205306d76", - Hostname: "bmath.wit.com", + Hostname: hostname, Comment: "this is a droplet for testing", } - return e + return d } func CreateSampleCluster(total int) *Cluster { @@ -23,10 +26,11 @@ func CreateSampleCluster(total int) *Cluster { c = new(Cluster) for i := 0; i < total; i++ { - d := CreateSampleDroplet() + hostname := fmt.Sprintf("bmath%d.wit.com", i) + d := CreateSampleDroplet(hostname) // e.Id += 1000 + int32(i) - d.Comment = "Sample Droplet " + string(i) + d.Comment = fmt.Sprintf("Sample Droplet %d", i) c.Droplets = append(c.Droplets, d) }