~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to tests/suite/base/t/overlong-mock.lua

  • Committer: Kay Roepke
  • Date: 2009-01-20 12:04:47 UTC
  • Revision ID: kay@mysql.com-20090120120447-fkoxq5ovwf9iyk4v
add the wrapper script/makefile fu to start mysql-proxy without having to set the environment variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--[[ $%BEGINLICENSE%$
2
 
 Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3
 
 
4
 
 This program is free software; you can redistribute it and/or
5
 
 modify it under the terms of the GNU General Public License as
6
 
 published by the Free Software Foundation; version 2 of the
7
 
 License.
8
 
 
9
 
 This program is distributed in the hope that it will be useful,
10
 
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
 GNU General Public License for more details.
13
 
 
14
 
 You should have received a copy of the GNU General Public License
15
 
 along with this program; if not, write to the Free Software
16
 
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
 
 02110-1301  USA
18
 
 
19
 
 $%ENDLICENSE%$ --]]
20
 
 
21
 
local proto = assert(require("mysql.proto"))
22
 
 
23
 
function connect_server()
24
 
        -- emulate a server
25
 
        proxy.response = {
26
 
                type = proxy.MYSQLD_PACKET_RAW,
27
 
                packets = {
28
 
                        proto.to_challenge_packet({
29
 
                                server_version = 50120
30
 
                        })
31
 
                }
32
 
        }
33
 
        return proxy.PROXY_SEND_RESULT
34
 
end
35
 
 
36
 
function read_query(packet)
37
 
        if packet:byte() ~= proxy.COM_QUERY then 
38
 
                proxy.response = {
39
 
                        type = proxy.MYSQLD_PACKET_OK
40
 
                }
41
 
                return proxy.PROXY_SEND_RESULT
42
 
        end
43
 
 
44
 
        if packet:sub(2, #("SELECT LENGTH") + 1) == "SELECT LENGTH" then
45
 
                proxy.response = {
46
 
                        type = proxy.MYSQLD_PACKET_OK,
47
 
                        resultset = {
48
 
                                fields = {
49
 
                                        { name = "length", type = proxy.MYSQL_TYPE_STRING },
50
 
                                },
51
 
                                rows = { { #packet }  }
52
 
                        }
53
 
                }
54
 
        elseif packet:sub(2, #("SELECT ") + 1) == "SELECT " then
55
 
                proxy.response = {
56
 
                        type = proxy.MYSQLD_PACKET_OK,
57
 
                        resultset = {
58
 
                                fields = {
59
 
                                        { name = "length", type = proxy.MYSQL_TYPE_STRING },
60
 
                                },
61
 
                                rows = { { packet:sub(2 + #("SELECT ")) } }
62
 
                        }
63
 
                }
64
 
        else
65
 
                proxy.response = {
66
 
                        type = proxy.MYSQLD_PACKET_ERR,
67
 
                        errmsg = "mock doesn't know how to handle query"
68
 
                }
69
 
        end
70
 
 
71
 
        return proxy.PROXY_SEND_RESULT
72
 
end
73