|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestConnGenAttributes(t *testing.T) { |
| 9 | + c := &Conn{ |
| 10 | + // example data from |
| 11 | + // https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse41 |
| 12 | + attributes: map[string]string{ |
| 13 | + "_os": "debian6.0", |
| 14 | + "_client_name": "libmysql", |
| 15 | + "_pid": "22344", |
| 16 | + "_client_version": "5.6.6-m9", |
| 17 | + "_platform": "x86_64", |
| 18 | + "foo": "bar", |
| 19 | + }, |
| 20 | + } |
| 21 | + |
| 22 | + data := c.genAttributes() |
| 23 | + fixture := []byte{ |
| 24 | + 0x61, 0x03, 0x5f, 0x6f, 0x73, 0x09, 0x64, 0x65, 0x62, 0x69, |
| 25 | + 0x61, 0x6e, 0x36, 0x2e, 0x30, 0x0c, 0x5f, 0x63, 0x6c, 0x69, 0x65, 0x6e, |
| 26 | + 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x08, 0x6c, 0x69, 0x62, 0x6d, 0x79, |
| 27 | + 0x73, 0x71, 0x6c, 0x04, 0x5f, 0x70, 0x69, 0x64, 0x05, 0x32, 0x32, 0x33, |
| 28 | + 0x34, 0x34, 0x0f, 0x5f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x76, |
| 29 | + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x08, 0x35, 0x2e, 0x36, 0x2e, 0x36, |
| 30 | + 0x2d, 0x6d, 0x39, 0x09, 0x5f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, |
| 31 | + 0x6d, 0x06, 0x78, 0x38, 0x36, 0x5f, 0x36, 0x34, 0x03, 0x66, 0x6f, 0x6f, |
| 32 | + 0x03, 0x62, 0x61, 0x72, |
| 33 | + } |
| 34 | + |
| 35 | + if !bytes.Equal(fixture, data) { |
| 36 | + t.Fatalf("unexpected attribute data\nexpected: %v\ngot: %v\n", fixture, data) |
| 37 | + } |
| 38 | +} |
0 commit comments