MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestGetStatementWithResultLimit

Function TestGetStatementWithResultLimit

backend/plugin/db/tidb/query_test.go:9–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestGetStatementWithResultLimit(t *testing.T) {
10 testCases := []struct {
11 stmt string
12 count int
13 want string
14 }{
15 {
16 stmt: "SELECT * FROM t;",
17 count: 10,
18 want: "SELECT * FROM `t` LIMIT 10",
19 },
20 {
21 stmt: "WITH a AS (SELECT * FROM t) SELECT * FROM a;",
22 count: 10,
23 want: "WITH `a` AS (SELECT * FROM `t`) SELECT * FROM `a` LIMIT 10",
24 },
25 {
26 stmt: "SELECT * FROM t1 UNION SELECT * FROM t2;",
27 count: 10,
28 want: "SELECT * FROM `t1` UNION SELECT * FROM `t2` LIMIT 10",
29 },
30 {
31 stmt: "SELECT * FROM t1 INTERSECT SELECT * FROM t2;",
32 count: 10,
33 want: "SELECT * FROM `t1` INTERSECT SELECT * FROM `t2` LIMIT 10",
34 },
35 {
36 stmt: "SELECT * FROM t LIMIT 5;",
37 count: 10,
38 want: "SELECT * FROM `t` LIMIT 5",
39 },
40 {
41 stmt: "SELECT * FROM t LIMIT 123;",
42 count: 10,
43 want: "SELECT * FROM `t` LIMIT 10",
44 },
45 {
46 stmt: "SELECT * FROM t WHERE nickname = 'bb'",
47 count: 10,
48 want: "SELECT * FROM `t` WHERE `nickname`='bb' LIMIT 10",
49 },
50 {
51 stmt: "SELECT 'Hello world'",
52 count: 10,
53 want: "SELECT 'Hello world' LIMIT 10",
54 },
55 }
56
57 for _, tc := range testCases {
58 got := getStatementWithResultLimit(tc.stmt, tc.count)
59 require.Equal(t, tc.want, got, tc.stmt)
60 }
61}

Callers

nothing calls this directly

Calls 2

EqualMethod · 0.65

Tested by

no test coverage detected