1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
package proto
import (
"testing"
"github.com/pion/stun"
)
func TestDontFragment(t *testing.T) {
var dontFrag DontFragment
t.Run("False", func(t *testing.T) {
m := new(stun.Message)
m.WriteHeader()
if dontFrag.IsSet(m) {
t.Error("should not be set")
}
})
t.Run("AddTo", func(t *testing.T) {
m := new(stun.Message)
if err := dontFrag.AddTo(m); err != nil {
t.Error(err)
}
m.WriteHeader()
t.Run("IsSet", func(t *testing.T) {
decoded := new(stun.Message)
if _, err := decoded.Write(m.Raw); err != nil {
t.Fatal("failed to decode message:", err)
}
if !dontFrag.IsSet(m) {
t.Error("should be set")
}
if wasAllocs(func() {
dontFrag.IsSet(m)
}) {
t.Error("unexpected allocations")
}
})
})
}
|