Skip to content

Commit

Permalink
Merge pull request Tantalor93#135 from Tantalor93/plottests
Browse files Browse the repository at this point in the history
add tests for plots
  • Loading branch information
Ondřej Benkovský authored Aug 18, 2023
2 parents 58f4df1 + cfd5af6 commit e825761
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions cmd/plot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package cmd

import (
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var timings = []Datapoint{
{Start: time.Now(), Duration: 100},
{Start: time.Now().Add(time.Second), Duration: 200},
{Start: time.Now().Add(2 * time.Second), Duration: 300},
{Start: time.Now().Add(3 * time.Second), Duration: 100},
{Start: time.Now().Add(4 * time.Second), Duration: 150},
{Start: time.Now().Add(5 * time.Second), Duration: 200},
{Start: time.Now().Add(6 * time.Second), Duration: 200},
{Start: time.Now().Add(7 * time.Second), Duration: 300},
{Start: time.Now().Add(8 * time.Second), Duration: 350},
{Start: time.Now().Add(9 * time.Second), Duration: 100},
{Start: time.Now().Add(10 * time.Second), Duration: 200},
}

var rcodes = map[int]int64{
0: 8,
2: 1,
3: 2,
}

func Test_plotHistogramLatency(t *testing.T) {
dir := t.TempDir()

file := dir + "/histogram-latency.png"
plotHistogramLatency(file, timings)

expected, err := os.ReadFile("test-histogram-latency.png")
require.NoError(t, err)

actual, err := os.ReadFile(file)
require.NoError(t, err)

assert.Equal(t, expected, actual, "generated histogram latency plot does not equal to expected 'test-histogram-latency.png'")
}

func Test_plotBoxPlotLatency(t *testing.T) {
dir := t.TempDir()

file := dir + "/boxplot-latency.png"
plotBoxPlotLatency(file, "127.0.0.1", timings)

expected, err := os.ReadFile("test-boxplot-latency.png")
require.NoError(t, err)

actual, err := os.ReadFile(file)
require.NoError(t, err)

assert.Equal(t, expected, actual, "generated boxplot latency plot does not equal to expected 'test-boxplot-latency.png'")
}

func Test_plotResponses(t *testing.T) {
dir := t.TempDir()

file := dir + "/responses-barchart.png"
plotResponses(file, rcodes)

expected, err := os.ReadFile("test-responses-barchart.png")
require.NoError(t, err)

actual, err := os.ReadFile(file)
require.NoError(t, err)

assert.Equal(t, expected, actual, "generated boxplot latency plot does not equal to expected 'test-responses-barchart.png'")
}

func Test_plotLineThroughput(t *testing.T) {
dir := t.TempDir()

file := dir + "/throughput-lineplot.png"
plotLineThroughput(file, timings)

expected, err := os.ReadFile("test-throughput-lineplot.png")
require.NoError(t, err)

actual, err := os.ReadFile(file)
require.NoError(t, err)

assert.Equal(t, expected, actual, "generated boxplot latency plot does not equal to expected 'test-throughput-lineplot.png'")
}

func Test_plotLineLatencies(t *testing.T) {
dir := t.TempDir()

file := dir + "/latency-lineplot.png"
plotLineLatencies(file, timings)

expected, err := os.ReadFile("test-latency-lineplot.png")
require.NoError(t, err)

actual, err := os.ReadFile(file)
require.NoError(t, err)

assert.Equal(t, expected, actual, "generated boxplot latency plot does not equal to expected 'test-latency-lineplot.png'")
}
Binary file added cmd/test-boxplot-latency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cmd/test-histogram-latency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cmd/test-latency-lineplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cmd/test-responses-barchart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cmd/test-throughput-lineplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e825761

Please sign in to comment.