mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Add tests
This commit is contained in:
parent
1bfad93d99
commit
fce5b00a4f
1 changed files with 34 additions and 0 deletions
34
benchmark_test.go
Normal file
34
benchmark_test.go
Normal 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)
|
||||
}
|
||||
Loading…
Reference in a new issue