forked from tursodatabase/libsql-shell-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot_command_shell_test.go
98 lines (73 loc) · 3.08 KB
/
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
package main_test
import (
"testing"
qt "github.com/frankban/quicktest"
"github.com/stretchr/testify/suite"
"github.com/libsql/libsql-shell-go/test/utils"
)
type RootCommandShellSuite struct {
suite.Suite
dbUri string
authToken string
tc *utils.DbTestContext
}
func NewRootCommandShellSuite(dbUri string, authToken string) *RootCommandShellSuite {
return &RootCommandShellSuite{dbUri: dbUri, authToken: authToken}
}
func (s *RootCommandShellSuite) SetupSuite() {
s.tc = utils.NewTestContext(s.T(), s.dbUri, s.authToken)
s.tc.DropAllTables()
}
func (s *RootCommandShellSuite) TearDownSuite() {
s.tc.Close()
}
func (s *RootCommandShellSuite) TearDownTest() {
s.tc.DropAllTables()
}
func (s *RootCommandShellSuite) Test_WhenCreateTable_ExpectDbHaveTheTable() {
outS, errS, err := s.tc.ExecuteShell([]string{"CREATE TABLE test (name STRING);", "SELECT * FROM test;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, utils.GetPrintTableOutput([]string{"name"}, [][]string{}))
}
func (s *RootCommandShellSuite) Test_WhenCreateTableAndInsertData_ExpectDbHaveTheTableWithTheData() {
outS, errS, err := s.tc.ExecuteShell([]string{"CREATE TABLE test (name STRING);", "INSERT INTO test VALUES ('test');", "SELECT * FROM test;"})
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 *RootCommandShellSuite) Test_WhenNoCommandsAreProvided_ExpectShellExecutedWithoutError() {
outS, errS, err := s.tc.ExecuteShell([]string{})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, "")
}
func (s *RootCommandShellSuite) Test_WhenExecuteInvalidStatement_ExpectError() {
outS, errS, err := s.tc.ExecuteShell([]string{"SELECTT 1;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(outS, qt.Equals, "")
s.tc.Assert(len(errS), qt.Not(qt.Equals), 0)
}
func (s *RootCommandShellSuite) Test_WhenTypingQuitCommand_ExpectShellNotRunFollowingCommands() {
outS, errS, err := s.tc.ExecuteShell([]string{".quit", "SELECT 1;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(outS, qt.Equals, "")
s.tc.Assert(errS, qt.Equals, "")
}
func (s *RootCommandShellSuite) TestRootCommandShell_WhenSplittingStatementsIntoMultipleLine_ExpectMergeLinesBeforeExecuting() {
s.tc.CreateSimpleTable("simple_table", []utils.SimpleTableEntry{{TextField: "value1", IntField: 1}})
outS, errS, err := s.tc.ExecuteShell([]string{"SELECT", "*", "FROM", "simple_table;"})
s.tc.Assert(err, qt.IsNil)
s.tc.Assert(errS, qt.Equals, "")
s.tc.Assert(outS, qt.Equals, utils.GetPrintTableOutput([]string{"id", "textField", "intField"}, [][]string{{"1", "value1", "1"}}))
}
func TestRootCommandShellSuite_WhenDbIsSQLite(t *testing.T) {
suite.Run(t, NewRootCommandShellSuite(t.TempDir()+"test.sqlite", ""))
}
func TestRootCommandShellSuite_WhenDbIsSqld(t *testing.T) {
testConfig := utils.GetTestConfig(t)
if testConfig.SkipSqldTests {
t.Skip("Skipping Sqld tests due configuration")
}
suite.Run(t, NewRootCommandShellSuite(testConfig.SqldDbUri, testConfig.AuthToken))
}