mirror of
				https://github.com/chaisql/chai.git
				synced 2025-10-31 19:02:48 +08:00 
			
		
		
		
	 4a6e68439a
			
		
	
	4a6e68439a
	
	
	
		
			
			All new error handling code now rely on internal/errors package which provides a compilation time toggle that enables to capture stacktraces for easier debugging while developing. It also comes with a new testutil/assert package which replaces the require package when it comes to checking or comparing errors and printing the stack traces if needed. Finally, the test target of the Makefile uses the debug build tag by default. A testnodebug target is also provided for convenience and to make sure no tests are broken due to not having used the internal/errors or testutil/assert package. See #431 for more details
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package parser_test
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/genjidb/genji/internal/query/statement"
 | |
| 	"github.com/genjidb/genji/internal/sql/parser"
 | |
| 	"github.com/genjidb/genji/internal/testutil/assert"
 | |
| 	"github.com/stretchr/testify/require"
 | |
| )
 | |
| 
 | |
| func TestParserDrop(t *testing.T) {
 | |
| 	tests := []struct {
 | |
| 		name     string
 | |
| 		s        string
 | |
| 		expected statement.Statement
 | |
| 		errored  bool
 | |
| 	}{
 | |
| 		{"Drop table", "DROP TABLE test", statement.DropTableStmt{TableName: "test"}, false},
 | |
| 		{"Drop table If not exists", "DROP TABLE IF EXISTS test", statement.DropTableStmt{TableName: "test", IfExists: true}, false},
 | |
| 		{"Drop index", "DROP INDEX test", statement.DropIndexStmt{IndexName: "test"}, false},
 | |
| 		{"Drop index if exists", "DROP INDEX IF EXISTS test", statement.DropIndexStmt{IndexName: "test", IfExists: true}, false},
 | |
| 		{"Drop index", "DROP SEQUENCE test", statement.DropSequenceStmt{SequenceName: "test"}, false},
 | |
| 		{"Drop index if exists", "DROP SEQUENCE IF EXISTS test", statement.DropSequenceStmt{SequenceName: "test", IfExists: true}, false},
 | |
| 	}
 | |
| 
 | |
| 	for _, test := range tests {
 | |
| 		t.Run(test.name, func(t *testing.T) {
 | |
| 			q, err := parser.ParseQuery(test.s)
 | |
| 			if test.errored {
 | |
| 				assert.Error(t, err)
 | |
| 				return
 | |
| 			}
 | |
| 			assert.NoError(t, err)
 | |
| 			require.Len(t, q.Statements, 1)
 | |
| 			require.EqualValues(t, test.expected, q.Statements[0])
 | |
| 		})
 | |
| 	}
 | |
| }
 |