Add tests

This commit is contained in:
Noah Hilverling 2019-02-26 09:37:21 +01:00
parent 1bfad93d99
commit fce5b00a4f

34
benchmark_test.go Normal file
View file

@ -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)
}