wifictld-analyzer/data/socket_msg_test.go

59 lines
2.1 KiB
Go
Raw Normal View History

2018-06-02 01:00:54 +02:00
package data
import (
"encoding/hex"
"log"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMsgIsTypes(t *testing.T) {
assert := assert.New(t)
types := SocketMSGType(5)
assert.True(types.Is(SocketMSGTypeRequest))
assert.False(types.Is(SocketMSGTypeResponse))
assert.True(types.Is(SocketMSGTypeClient))
assert.False(types.Is(SocketMSGTypeStats))
assert.Equal(SocketMSGType(5), SocketMSGType(SocketMSGTypeRequest|SocketMSGTypeClient))
}
func TestMsgString(t *testing.T) {
assert := assert.New(t)
msg := SocketMSG{
Types: SocketMSGTypeRequest | SocketMSGTypeResponse | SocketMSGTypeClient,
Client: &WifiClient{
FreqHighest: 2464,
},
}
assert.Equal("request response client(mac= freq=2464 ssi_l=0 ssi_h=0 tprobe=0 tauth=0 authed=false time=0001-01-01 00:00:00 +0000 UTC) ", msg.String())
}
func TestMsgMarshal(t *testing.T) {
assert := assert.New(t)
dst := make([]byte, MaxDataGramSize)
_, err := hex.Decode(dst, []byte("00000005f0cfa13375295b0f8b92000000000101099effa300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
if err != nil {
log.Fatal(err)
}
msg, _ := NewSocketMSG(dst)
assert.Equal(SocketMSGType(SocketMSGTypeRequest|SocketMSGTypeClient), msg.Types)
assert.Equal("f0:cf:a1:33:75:29", msg.Client.Addr.String())
assert.Equal("2018-05-31T05:43:46Z", msg.Client.Time.UTC().Format(time.RFC3339))
assert.Equal(0, int(msg.Client.TryProbe))
assert.Equal(0, int(msg.Client.TryAuth))
assert.True(msg.Client.Connected)
assert.True(msg.Client.Authed)
assert.Equal(2462, int(msg.Client.FreqHighest))
assert.Equal(-93, int(msg.Client.SignalLowFreq))
assert.Equal(0, int(msg.Client.SignalHighFreq))
result, _ := msg.Marshal()
assert.Equal(dst, result)
}