network/frame/authentication_frame_test.go

24 lines
576 B
Go
Raw Normal View History

2023-04-05 16:15:59 +08:00
package frame
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAuthenticationFrame(t *testing.T) {
m := NewAuthenticationFrame("token", "a")
assert.Equal(t, []byte{
0x80 | byte(TagOfAuthenticationFrame), 0xa,
byte(TagOfAuthenticationName), 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e,
byte(TagOfAuthenticationPayload), 0x01, 0x61,
},
m.Encode(),
)
authenticate, err := DecodeToAuthenticationFrame(m.Encode())
assert.NoError(t, err)
assert.EqualValues(t, "token", authenticate.AuthName())
assert.EqualValues(t, "a", authenticate.AuthPayload())
}