change sample hostname
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bcc97a550a
commit
aa70a02dd8
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue