From fce5b00a4fb1558f0f6d1a36f633bd3d77060c07 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Tue, 26 Feb 2019 09:37:21 +0100 Subject: [PATCH] Add tests --- benchmark_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 benchmark_test.go diff --git a/benchmark_test.go b/benchmark_test.go new file mode 100644 index 00000000..b61fe956 --- /dev/null +++ b/benchmark_test.go @@ -0,0 +1,34 @@ +package icingadb_utils + +import ( + "github.com/stretchr/testify/assert" + "testing" + "time" +) + +func TestBenchmark(t *testing.T) { + benchmarc := NewBenchmark() + time.Sleep(1 * time.Second) + benchmarc.Stop() + dur, _ := time.ParseDuration(benchmarc.String()) + assert.InDelta(t, (1 * time.Second).Seconds(), dur.Seconds(), (10 * time.Millisecond).Seconds()) + + benchmarc = NewBenchmark() + time.Sleep(250 * time.Millisecond) + benchmarc.Stop() + dur, _ = time.ParseDuration(benchmarc.String()) + assert.InDelta(t, (250 * time.Millisecond).Seconds(), dur.Seconds(), (10 * time.Millisecond).Seconds()) + + benchmarc = NewBenchmark() + time.Sleep(500 * time.Nanosecond) + benchmarc.Stop() + dur, _ = time.ParseDuration(benchmarc.String()) + assert.InDelta(t, (500 * time.Nanosecond).Seconds(), dur.Seconds(), (10 * time.Millisecond).Seconds()) + + benchmarc = NewBenchmark() + benchmarc.diff = time.Second * 10 + assert.Equal(t, float64(10), benchmarc.Seconds()) + + by, _ := benchmarc.MarshalText() + assert.Equal(t, []uint8([]byte{0x31, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x73}), by) +} \ No newline at end of file