MCPcopy Create free account
hub / github.com/cloudspannerecosystem/spanner-cli / TestBuildCommands

Function TestBuildCommands

cli_test.go:40–118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestBuildCommands(t *testing.T) {
41 tests := []struct {
42 Input string
43 Expected []*command
44 ExpectError bool
45 }{
46 {Input: `SELECT * FROM t1;`, Expected: []*command{{&SelectStatement{"SELECT * FROM t1"}, false}}},
47 {Input: `CREATE TABLE t1;`, Expected: []*command{{&BulkDdlStatement{[]string{"CREATE TABLE t1"}}, false}}},
48 {
49 Input: `CREATE TABLE t1(pk INT64) PRIMARY KEY(pk); ALTER TABLE t1 ADD COLUMN col INT64; CREATE INDEX i1 ON t1(col); DROP INDEX i1; DROP TABLE t1;`,
50 Expected: []*command{{&BulkDdlStatement{[]string{
51 "CREATE TABLE t1(pk INT64) PRIMARY KEY(pk)",
52 "ALTER TABLE t1 ADD COLUMN col INT64",
53 "CREATE INDEX i1 ON t1(col)",
54 "DROP INDEX i1",
55 "DROP TABLE t1",
56 }}, false}},
57 },
58 {
59 Input: `CREATE TABLE t1(pk INT64) PRIMARY KEY(pk);
60 CREATE TABLE t2(pk INT64) PRIMARY KEY(pk);
61 SELECT * FROM t1\G
62 DROP TABLE t1;
63 DROP TABLE t2;
64 SELECT 1;`,
65 Expected: []*command{
66 {&BulkDdlStatement{[]string{"CREATE TABLE t1(pk INT64) PRIMARY KEY(pk)", "CREATE TABLE t2(pk INT64) PRIMARY KEY(pk)"}}, false},
67 {&SelectStatement{"SELECT * FROM t1"}, true},
68 {&BulkDdlStatement{[]string{"DROP TABLE t1", "DROP TABLE t2"}}, false},
69 {&SelectStatement{"SELECT 1"}, false},
70 },
71 },
72 {
73 Input: `
74 CREATE TABLE t1(pk INT64 /* NOT NULL*/, col INT64) PRIMARY KEY(pk);
75 INSERT t1(pk/*, col*/) VALUES(1/*, 2*/);
76 UPDATE t1 SET col = /* pk + */ col + 1 WHERE TRUE;
77 DELETE t1 WHERE TRUE /* AND pk = 1 */;
78 SELECT 0x1/**/A`,
79 Expected: []*command{
80 {&BulkDdlStatement{[]string{"CREATE TABLE t1(pk INT64 , col INT64) PRIMARY KEY(pk)"}}, false},
81 {&DmlStatement{"INSERT t1(pk/*, col*/) VALUES(1/*, 2*/)"}, false},
82 {&DmlStatement{"UPDATE t1 SET col = /* pk + */ col + 1 WHERE TRUE"}, false},
83 {&DmlStatement{"DELETE t1 WHERE TRUE /* AND pk = 1 */"}, false},
84 {&SelectStatement{"SELECT 0x1/**/A"}, false},
85 },
86 },
87 {
88 // spanner-cli don't permit empty statements.
89 Input: `SELECT 1; /* comment */; SELECT 2`,
90 ExpectError: true,
91 },
92 {
93 Input: `SELECT 1; /* comment 1 */; /* comment 2 */`,
94 ExpectError: true,
95 },
96 {
97 // A comment after the last semicolon is permitted.

Callers

nothing calls this directly

Calls 1

buildCommandsFunction · 0.85

Tested by

no test coverage detected