forked from tursodatabase/libsql-shell-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_root_command_shell_test.go
372 lines (293 loc) · 18.7 KB
/
db_root_command_shell_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
package main_test
import (
"strings"
"testing"
qt "github.com/frankban/quicktest"
"github.com/stretchr/testify/suite"
"github.com/libsql/libsql-shell-go/test/utils"
)
type DBRootCommandShellSuite struct {
suite.Suite
dbUri string
authToken string
tc *utils.DbTestContext
}
func NewDBRootCommandShellSuite(dbUri string) *DBRootCommandShellSuite {
return &DBRootCommandShellSuite{dbUri: dbUri}
}
func (s *DBRootCommandShellSuite) SetupSuite() {
s.tc = utils.NewTestContext(s.T(), s.dbUri, s.authToken)
s.tc.DropAllTables()
}
func (s *DBRootCommandShellSuite) TearDownTest() {
s.tc.DropAllTables()
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithTwoTables_WhenCallDotTablesCommand_ExpectAListContainingTheTableNames() {
s.tc.CreateEmptySimpleTable("simple_table")
s.tc.CreateEmptySimpleTable("another_simple_table")
outTables, errS, err := s.tc.ExecuteShell([]string{".tables"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outTables, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{"another_simple_table\nsimple_table"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithTwoTables_WhenCallDotSchemaCommand_ExpectAListContainingTheSchemas() {
s.tc.CreateEmptySimpleTable("simple_table")
s.tc.CreateEmptySimpleTable("another_simple_table")
outSchema, errS, err := s.tc.ExecuteShell([]string{".schema"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outSchema, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{"CREATE TABLE another_simple_table (id INTEGER PRIMARY KEY, textField TEXT, intField INTEGER);\nCREATE TABLE simple_table (id INTEGER PRIMARY KEY, textField TEXT, intField INTEGER);"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithTwoTables_WhenCallDotSchemaCommandWithPattern_ExpectToReturnOneSchema() {
s.tc.CreateEmptySimpleTable("simple_table")
s.tc.CreateEmptySimpleTable("another_simple_table")
outSchema, errS, err := s.tc.ExecuteShell([]string{".schema simple_table"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outSchema, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{"CREATE TABLE simple_table (id INTEGER PRIMARY KEY, textField TEXT, intField INTEGER);"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithThreeTables_WhenCallDotSchemaCommandWithPartialDbName_ExpectToReturnTwoSchemas() {
s.tc.CreateEmptySimpleTable("simple_table")
s.tc.CreateEmptySimpleTable("test_table_one")
s.tc.CreateEmptySimpleTable("test_table_two")
outSchema, errS, err := s.tc.ExecuteShell([]string{".schema test%"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outSchema, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{"CREATE TABLE test_table_one (id INTEGER PRIMARY KEY, textField TEXT, intField INTEGER);\nCREATE TABLE test_table_two (id INTEGER PRIMARY KEY, textField TEXT, intField INTEGER);"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithTwoTables_WhenCallDotSchemaCommandWithPatternThatDoesNotMatch_ExpectEmptyReturn() {
s.tc.CreateEmptySimpleTable("simple_table")
s.tc.CreateEmptySimpleTable("another_simple_table")
outSchema, errS, err := s.tc.ExecuteShell([]string{".schema non_existing_table"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outSchema, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{""}}))
}
func (s *DBRootCommandShellSuite) Test_WhenCallDotHelpCommand_ExpectAListWithAllAvailableCommands() {
outS, errS, err := s.tc.ExecuteShell([]string{".help"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
expectedHelp :=
`.dump Render database content as SQL
.help List of all available commands.
.indexes List indexes in a table or database
.mode Set output mode
.quit Exit this program
.read Execute commands from a file
.schema Show table schemas.
.tables List all existing tables in the database.`
s.tc.Assert(outS, qt.Equals, expectedHelp)
}
func (s *DBRootCommandShellSuite) Test_GivenAEmptyDb_WhenCallDotReadCommand_ExpectToSeeATableWithOneEntry() {
content := `CREATE TABLE IF NOT EXISTS testread (name TEXT);
/* Comment in the middle of the file.*/
INSERT INTO testread VALUES("test");
SELECT * FROM testread;`
file, filePath := s.tc.CreateTempFile(content)
defer file.Close()
outS, errS, err := s.tc.ExecuteShell([]string{".read " + filePath})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, utils.GetPrintTableOutput([]string{"NAME"}, [][]string{{"test"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenAEmptyDb_WhenCallDotReadCommandPassingANonExistingFile_ExpectToReturnAnErrorMessage() {
outS, errS, err := s.tc.ExecuteShell([]string{".read nonExistingFile.txt"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "Error: open nonExistingFile.txt: no such file or directory")
s.tc.Assert(outS, qt.Equals, "")
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithTwoTables_WhenCreateTwoIndexesAndCallDotIndexesCommand_ExpectToReturnTheIndexes() {
s.tc.CreateSimpleTable("simple_table", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
s.tc.CreateSimpleTable("simple_table_2", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
_, errS, err := s.tc.Execute("CREATE INDEX idx_textfield on simple_table (TextField);CREATE INDEX idx_intfield on simple_table_2 (IntField)")
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{".indexes"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{"idx_textfield\nidx_intfield"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithThreeTables_WhenCreateThreeIndexesAndCallDotIndexesCommandPassingExactTableName_ExpectToReturnJustOneIndex() {
s.tc.CreateSimpleTable("simple_table", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
s.tc.CreateSimpleTable("simple_table_2", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
s.tc.CreateSimpleTable("simple_table_3", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
_, errS, err := s.tc.Execute("CREATE INDEX idx_textfield on simple_table (TextField);CREATE INDEX idx_intfield on simple_table_2 (IntField);CREATE INDEX idx_intfield_third_table on simple_table_3 (IntField)")
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{".indexes simple_table_3"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{"idx_intfield_third_table"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithThreeTables_WhenCreateThreeIndexesAndCallDotIndexesCommandPassingPartOfTableName_ExpectToReturnTwoIndexes() {
s.tc.CreateSimpleTable("simple_table", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
s.tc.CreateSimpleTable("simple_table_2", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
s.tc.CreateSimpleTable("another_simple_table", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
_, errS, err := s.tc.Execute("CREATE INDEX idx_textfield on simple_table (TextField);CREATE INDEX idx_intfield on simple_table_2 (IntField);CREATE INDEX idx_intfield_another_table on another_simple_table (IntField)")
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{".indexes simple%"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{"idx_textfield\nidx_intfield"}}))
}
func (s *DBRootCommandShellSuite) Test_GivenADBWithATable_WhenCreateAIndexAndCallDotIndexesCommandPassingAWrongTableName_ExpectEmptyReturn() {
s.tc.CreateSimpleTable("simple_table", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}, {TextField: "value2", IntField: 2}})
_, errS, err := s.tc.Execute("CREATE INDEX idx_textfield on simple_table (TextField);")
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{".indexes nonExistingTable"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, utils.GetPrintTableOutput([]string{""}, [][]string{{""}}))
}
func (s *DBRootCommandShellSuite) Test_GivenAEmptyTable_WhenCallDotDumpCommand_ExpectNoErrors() {
s.tc.CreateEmptyAllTypesTable("alltypes")
outS, errS, err := s.tc.ExecuteShell([]string{".dump"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
prefix := "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\nCREATE TABLE"
if !strings.HasSuffix(s.dbUri, "test.sqlite") {
prefix += " if not exists libsql_wasm_func_table (name text primary key, body text) without rowid;\nCREATE TABLE if not exists"
}
expected := " alltypes (textNullable text, textNotNullable text NOT NULL, textWithDefault text DEFAULT 'defaultValue', \n\tintNullable INTEGER, intNotNullable INTEGER NOT NULL, intWithDefault INTEGER DEFAULT '0', \n\tfloatNullable REAL, floatNotNullable REAL NOT NULL, floatWithDefault REAL DEFAULT '0.0', \n\tunknownNullable NUMERIC, unknownNotNullable NUMERIC NOT NULL, unknownWithDefault NUMERIC DEFAULT 0.0, \n\tblobNullable BLOB, blobNotNullable BLOB NOT NULL, blobWithDefault BLOB DEFAULT 'x\"0\"');\nCOMMIT;"
s.tc.AssertSqlEquals(outS, prefix+expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableConainingRandomFields_WhenInsertAndCallDotDumpCommand_ExpectNoErrors() {
_, errS, err := s.tc.Execute(`CREATE TABLE alltypes (t text, i integer, r real, b blob);
INSERT INTO alltypes VALUES ('text', 99, 3.14, x'0123456789ABCDEF')`)
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{".dump"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
prefix := "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\nCREATE TABLE"
if !strings.HasSuffix(s.dbUri, "test.sqlite") {
prefix += " if not exists libsql_wasm_func_table (name text primary key, body text) without rowid;\nCREATE TABLE if not exists"
}
expected := " alltypes (t text, i integer, r real, b blob);\nINSERT INTO alltypes VALUES('text',99,3.14,X'0123456789ABCDEF');\nCOMMIT;"
s.tc.AssertSqlEquals(outS, prefix+expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableConainingFieldsWithALLTypes_WhenInsertAndCallDotDumpCommand_ExpectNoErrors() {
s.tc.CreateAllTypesTable("alltypes", []utils.AllTypesTableEntry{
{TextNotNullable: "text2", IntNotNullable: 0, FloatNotNullable: 1.5, UnknownNotNullable: 0.0, BlobNotNullable: "0123456789ABCDEF"},
})
outS, errS, err := s.tc.ExecuteShell([]string{".dump"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
prefix := "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\nCREATE TABLE"
if !strings.HasSuffix(s.dbUri, "test.sqlite") {
prefix += " if not exists libsql_wasm_func_table (name text primary key, body text) without rowid;\nCREATE TABLE if not exists"
}
expected := " alltypes (textNullable text, textNotNullable text NOT NULL, textWithDefault text DEFAULT 'defaultValue', \n\tintNullable INTEGER, intNotNullable INTEGER NOT NULL, intWithDefault INTEGER DEFAULT '0', \n\tfloatNullable REAL, floatNotNullable REAL NOT NULL, floatWithDefault REAL DEFAULT '0.0', \n\tunknownNullable NUMERIC, unknownNotNullable NUMERIC NOT NULL, unknownWithDefault NUMERIC DEFAULT 0.0, \n\tblobNullable BLOB, blobNotNullable BLOB NOT NULL, blobWithDefault BLOB DEFAULT 'x\"0\"');\nINSERT INTO alltypes VALUES(NULL,'text2','defaultValue',NULL,0,0,NULL,1.5,0,NULL,0,0,NULL,X'0123456789ABCDEF','x\"0\"');\nCOMMIT;"
s.tc.AssertSqlEquals(outS, prefix+expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableWithRecords_WhenCreateIndexAndCallDotDumpCommand_ExpectNoErrors() {
s.tc.CreateEmptyAllTypesTable("alltypes")
_, errS, err := s.tc.Execute("CREATE INDEX idx_textNullable on alltypes (textNullable);CREATE INDEX idx_intNotNullable on alltypes (intNotNullable) WHERE intNotNullable > 1;")
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{".dump"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
prefix := "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\nCREATE TABLE"
if !strings.HasSuffix(s.dbUri, "test.sqlite") {
prefix += " if not exists libsql_wasm_func_table (name text primary key, body text) without rowid;\nCREATE TABLE if not exists"
}
expected := " alltypes (textNullable text, textNotNullable text NOT NULL, textWithDefault text DEFAULT 'defaultValue', \n\tintNullable INTEGER, intNotNullable INTEGER NOT NULL, intWithDefault INTEGER DEFAULT '0', \n\tfloatNullable REAL, floatNotNullable REAL NOT NULL, floatWithDefault REAL DEFAULT '0.0', \n\tunknownNullable NUMERIC, unknownNotNullable NUMERIC NOT NULL, unknownWithDefault NUMERIC DEFAULT 0.0, \n\tblobNullable BLOB, blobNotNullable BLOB NOT NULL, blobWithDefault BLOB DEFAULT 'x\"0\"');\nCREATE INDEX idx_textNullable on alltypes (textNullable);\nCREATE INDEX idx_intNotNullable on alltypes (intNotNullable) WHERE intNotNullable > 1;\nCOMMIT;"
s.tc.AssertSqlEquals(outS, prefix+expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableWithRecordsWithSingleQuote_WhenCalllDotDumpCommand_ExpectSingleQuoteScape() {
s.tc.CreateEmptySimpleTable("t")
_, errS, err := s.tc.Execute("INSERT INTO t VALUES(0, \"x'x\", 0)")
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{".dump"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
prefix := "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\nCREATE TABLE"
if !strings.HasSuffix(s.dbUri, "test.sqlite") {
prefix += " if not exists libsql_wasm_func_table (name text primary key, body text) without rowid;\nCREATE TABLE if not exists"
}
expected := " t (id integer primary key, textfield text, intfield integer);\ninsert into t values(0,'x''x',0);\ncommit;"
s.tc.AssertSqlEquals(outS, prefix+expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableNameStartingWithNumber_WhenCalllDotDumpCommand_ExpectCorrectFormat() {
s.tc.CreateSimpleTable("\"8test\"", []utils.SimpleTableEntry{{TextField: "Value", IntField: 1}})
outS, errS, err := s.tc.ExecuteShell([]string{".dump"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
prefix := "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\nCREATE TABLE"
if !strings.HasSuffix(s.dbUri, "test.sqlite") {
prefix += " if not exists libsql_wasm_func_table (name text primary key, body text) without rowid;\nCREATE TABLE if not exists"
}
expected := " \"8test\" (id integer primary key, textfield text, intfield integer);\ninsert into \"8test\" values(1,'value',1);\ncommit;"
s.tc.AssertSqlEquals(outS, prefix+expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableNameWithSpecialCharacters_WhenCallDotDumpCommand_ExpectCorrectFormat() {
s.tc.CreateSimpleTable("\"t+e(s!t?\"", []utils.SimpleTableEntry{{TextField: "Value", IntField: 1}})
outS, errS, err := s.tc.ExecuteShell([]string{".dump"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
prefix := "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\nCREATE TABLE"
if !strings.HasSuffix(s.dbUri, "test.sqlite") {
prefix += " if not exists libsql_wasm_func_table (name text primary key, body text) without rowid;\nCREATE TABLE if not exists"
}
expected := " \"t+e(s!t?\" (id integer primary key, textfield text, intfield integer);\ninsert into \"t+e(s!t?\" values(1,'value',1);\ncommit;"
s.tc.AssertSqlEquals(outS, prefix+expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableWithRecordsWithSingleQuote_WhenCalllSelectAllFromTable_ExpectSingleQuoteScape() {
s.tc.CreateEmptySimpleTable("t")
_, errS, err := s.tc.Execute("INSERT INTO t VALUES (0, \"x'x\", 0)")
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
outS, errS, err := s.tc.ExecuteShell([]string{"SELECT * FROM t;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
expected := "id textfield intfield \n0 x'x 0"
s.tc.AssertSqlEquals(outS, expected)
}
func (s *DBRootCommandShellSuite) Test_GivenATableWithRecord_WhenCallDotModeCSVAndSelect_ExpectNoErrors() {
s.tc.CreateSimpleTable("simple_table", []utils.SimpleTableEntry{{TextField: "value \"1", IntField: 1}, {TextField: "value, 2", IntField: 2}})
outS, errSMode, err := s.tc.ExecuteShell([]string{".mode csv", "SELECT * from simple_table;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errSMode, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, "id,textField,intField\n1,\"value \"\"1\",1\n2,\"value, 2\",2")
}
func (s *DBRootCommandShellSuite) Test_GivenAnEmptyTable_WhenCallDotModeCSVAndSelect_ExpectNoErrors() {
s.tc.CreateEmptySimpleTable("simple_table")
outS, errSMode, err := s.tc.ExecuteShell([]string{".mode csv", "SELECT * from simple_table;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errSMode, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, "id,textField,intField")
}
func (s *DBRootCommandShellSuite) Test_GivenATableWithRecords_WhenCallDotModeJSONAndSelect_ExpectNoErrors() {
s.tc.CreateSimpleTable("simple_table", []utils.SimpleTableEntry{{TextField: "value", IntField: 1}, {TextField: "value2", IntField: 2}})
outS, errSMode, err := s.tc.ExecuteShell([]string{".mode json", "SELECT * from simple_table;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errSMode, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, `[{"id":"1","intField":"1","textField":"value"},{"id":"2","intField":"2","textField":"value2"}]`)
}
func (s *DBRootCommandShellSuite) Test_GivenAnEmptyTable_WhenCallDotModeJSONAndSelect_ExpectEmptyReturn() {
s.tc.CreateEmptySimpleTable("simple_table")
outS, errSMode, err := s.tc.ExecuteShell([]string{".mode json", "SELECT * from simple_table;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errSMode, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, "")
}
func (s *DBRootCommandShellSuite) Test_WhenCallACommandThatDoesNotExist_ExpectToReturnAnErrorMessage() {
outS, errS, err := s.tc.ExecuteShell([]string{".nonExistingCommand"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, `Error: unknown command or invalid arguments: ".nonExistingCommand". Enter ".help" for help`)
s.tc.Assert(outS, qt.Equals, "")
}
func TestDBRootCommandShellSuite_WhenDbIsSQLite(t *testing.T) {
suite.Run(t, NewDBRootCommandShellSuite(t.TempDir()+"test.sqlite"))
}
func TestDBRootCommandShellSuite_WhenDbIsSqld(t *testing.T) {
testConfig := utils.GetTestConfig(t)
if testConfig.SkipSqldTests {
t.Skip("Skipping SQLD tests due configuration")
}
suite.Run(t, NewDBRootCommandShellSuite(testConfig.SqldDbUri))
}