forked from go-mysql-org/go-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
36 lines (29 loc) · 960 Bytes
/
auth_test.go
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
package client
import (
"testing"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/stretchr/testify/require"
)
func TestConnGenAttributes(t *testing.T) {
c := &Conn{
// example data from
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse41
attributes: map[string]string{
"_os": "debian6.0",
"_client_name": "libmysql",
"_pid": "22344",
"_client_version": "5.6.6-m9",
"_platform": "x86_64",
"foo": "bar",
},
}
data := c.genAttributes()
// the order of the attributes map cannot be guaranteed so to test the content
// of the attribute data we need to check its partial contents
require.Len(t, data, 98)
require.Equal(t, byte(0x61), data[0])
for k, v := range c.attributes {
fixt := append(mysql.PutLengthEncodedString([]byte(k)), mysql.PutLengthEncodedString([]byte(v))...)
require.Subset(t, data, fixt)
}
}