Files
stun/attributes_test.go
2017-02-11 08:17:00 +03:00

37 lines
646 B
Go

package stun
import (
"testing"
)
func BenchmarkMessage_GetNotFound(b *testing.B) {
m := New()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
m.Get(AttrRealm)
}
}
func TestMessage_GetNoAllocs(t *testing.T) {
m := New()
NewSoftware("c").AddTo(m)
m.WriteHeader()
t.Run("Default", func(t *testing.T) {
allocs := testing.AllocsPerRun(10, func() {
m.Get(AttrSoftware)
})
if allocs > 0 {
t.Error("allocated memory, but should not")
}
})
t.Run("Not found", func(t *testing.T) {
allocs := testing.AllocsPerRun(10, func() {
m.Get(AttrOrigin)
})
if allocs > 0 {
t.Error("allocated memory, but should not")
}
})
}