func uploadPlot(dataPoints []*data.Point, s3Config *uploader.Config, cpuCsv []byte) { ag := aggregator.New(dataPoints, time.Duration(*interval)*time.Second) report := ag.Data() filename := time.Now().UTC().Format(time.RFC3339) csvData := report.GenerateCSV() loc, err := uploader.Upload(s3Config, bytes.NewBuffer(csvData), filename+".csv", false) if err != nil { fmt.Fprintf(os.Stderr, "uploading to s3 error: %s\n", err) os.Exit(1) } fmt.Fprintf(os.Stdout, "csv uploaded to %s\n", loc) fmt.Fprintln(os.Stderr, "Generating plot from csv data") plotBuffer, err := plotgen.Generate(filename, csvData, cpuCsv, *comparisonFile) if err != nil { fmt.Fprintf(os.Stderr, "failed to generate plot: %s\n", err) os.Exit(1) } loc, err = uploader.Upload(s3Config, plotBuffer, filename+".png", true) if err != nil { fmt.Fprintf(os.Stderr, "uploading to s3 error: %s\n", err) os.Exit(1) } fmt.Fprintf(os.Stdout, "png uploaded to %s\n", loc) }
const comparisonCSV = ` throughput,latency 100, 0.01 200, 0.02 300, 0.03 400, 0.04 500, 0.05 600, 0.06 ` var _ = Describe("Plotgen", func() { Describe("Generate", func() { It("returns a valid PNG plot", func() { points := testData(10) plotReader, err := plotgen.Generate("test", points.GenerateCSV(), []byte(cpuCSV), "") Expect(err).NotTo(HaveOccurred()) plotBytes, err := ioutil.ReadAll(plotReader) Expect(err).NotTo(HaveOccurred()) Expect(http.DetectContentType(plotBytes)).To(Equal("image/png")) }) Context("with a valid comparison and cpu file", func() { var comparisonFilePath string BeforeEach(func() { comparisonFile, err := ioutil.TempFile("", "comparison.csv") Expect(err).ToNot(HaveOccurred()) comparisonFile.WriteString(comparisonCSV)