Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed view test script #398

Merged
merged 2 commits into from Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 30 additions & 6 deletions enginetest/enginetests.go
Expand Up @@ -939,22 +939,38 @@ func TestScriptWithEngine(t *testing.T, e *sqle.Engine, harness Harness, script
}
}

// This method is the only place we can reliably test newly created views, because view definitions live in the
// context, as opposed to being defined by integrators with a ViewDatabase interface, and we lose that context with
// our standard method of using a new context object per query.
// TODO: fix this by introducing sql.ViewDatabase
func TestViews(t *testing.T, harness Harness) {
require := require.New(t)

e := NewEngine(t, harness)
ctx := NewContext(harness)

// nested views
_, iter, err := e.Query(ctx, "CREATE VIEW myview2 AS SELECT * FROM myview WHERE i = 1")
require.NoError(err)
iter.Close(ctx)

RunQueryWithContext(t, e, ctx, "CREATE VIEW myview2 AS SELECT * FROM myview WHERE i = 1")
for _, testCase := range ViewTests {
t.Run(testCase.Query, func(t *testing.T) {
TestQueryWithContext(t, ctx, e, testCase.Query, testCase.Expected, nil, testCase.Bindings)
})
}

// Views with non-standard select statements
RunQueryWithContext(t, e, ctx, "create view unionView as (select * from myTable order by i limit 1) union all (select * from mytable order by i limit 1)")
t.Run("select * from unionview order by i", func(t *testing.T) {
TestQueryWithContext(
t,
ctx,
e,
"select * from unionview order by i",
[]sql.Row{
{1, "first row"},
{1, "first row"},
},
nil,
nil,
)
})
}

func TestVersionedViews(t *testing.T, harness Harness) {
Expand Down Expand Up @@ -2674,6 +2690,14 @@ func RunQuery(t *testing.T, e *sqle.Engine, harness Harness, query string) {
require.NoError(t, err)
}

// RunQueryWithContext runs the query given and asserts that it doesn't result in an error.
func RunQueryWithContext(t *testing.T, e *sqle.Engine, ctx *sql.Context, query string) {
_, iter, err := e.Query(ctx, query)
require.NoError(t, err)
_, err = sql.RowIterToRows(ctx, iter)
require.NoError(t, err)
}

// AssertErr asserts that the given query returns an error during its execution, optionally specifying a type of error.
func AssertErr(t *testing.T, e *sqle.Engine, harness Harness, query string, expectedErrKind *errors.Kind, errStrs ...string) {
ctx := NewContext(harness)
Expand Down
4 changes: 1 addition & 3 deletions enginetest/memoryharness.go
Expand Up @@ -49,9 +49,7 @@ func NewDefaultMemoryHarness() *MemoryHarness {
return NewMemoryHarness("default", 1, testNumPartitions, true, nil)
}

var skippedQueries = []string{
"select * from unionview", // memory views only persist for a single session
}
var skippedQueries = []string{}

func (m *MemoryHarness) SkipQueryTest(query string) bool {
for _, skippedQuery := range skippedQueries {
Expand Down
17 changes: 0 additions & 17 deletions enginetest/script_queries.go
Expand Up @@ -755,21 +755,4 @@ var ScriptTests = []ScriptTest{
},
},
},
{
Name: "Create union view",
SetUpScript: []string{
"create table myTable (i int primary key, s varchar(100))",
"insert into myTable values (1, 'first row'), (2, 'second row')",
"create view unionView as (select * from myTable order by i limit 1) union all (select * from mytable order by i limit 1)",
},
Assertions: []ScriptTestAssertion{
{
Query: "select * from unionView order by i",
Expected: []sql.Row{
{1, "first row"},
{1, "first row"},
},
},
},
},
}