Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions enginetest/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,8 @@ func TestOrderByGroupBy(t *testing.T, harness Harness) {
})
require.NoError(err)

ctx := harness.NewContext()

InsertRows(
t, ctx, mustInsertableTable(t, table),
t, NewContext(harness), mustInsertableTable(t, table),
sql.NewRow(int64(3), "red"),
sql.NewRow(int64(4), "red"),
sql.NewRow(int64(5), "orange"),
Expand Down Expand Up @@ -986,21 +984,41 @@ func TestTransactionScriptWithEngine(t *testing.T, e *sqle.Engine, harness Harne
assertions := script.Assertions

for _, assertion := range assertions {
clientSession, ok := clientSessions[assertion.Client]
client := getClient(assertion.Query)

clientSession, ok := clientSessions[client]
if !ok {
clientSession = NewSession(harness)
clientSessions[assertion.Client] = clientSession
}
if assertion.ExpectedErr != nil {
AssertErr(t, e, harness, assertion.Query, assertion.ExpectedErr)
} else if assertion.ExpectedErrStr != "" {
AssertErr(t, e, harness, assertion.Query, nil, assertion.ExpectedErrStr)
} else if assertion.ExpectedWarning != 0 {
AssertWarningAndTestQuery(t, e, nil, harness, assertion.Query, assertion.Expected, nil, assertion.ExpectedWarning)
} else {
TestQueryWithContext(t, clientSession, e, assertion.Query, assertion.Expected, nil, nil)
clientSessions[client] = clientSession
}

t.Run(assertion.Query, func(t *testing.T) {
if assertion.ExpectedErr != nil {
AssertErrWithCtx(t, e, clientSession, assertion.Query, assertion.ExpectedErr)
} else if assertion.ExpectedErrStr != "" {
AssertErrWithCtx(t, e, clientSession, assertion.Query, nil, assertion.ExpectedErrStr)
} else if assertion.ExpectedWarning != 0 {
AssertWarningAndTestQuery(t, e, nil, harness, assertion.Query, assertion.Expected, nil, assertion.ExpectedWarning)
} else {
TestQueryWithContext(t, clientSession, e, assertion.Query, assertion.Expected, nil, nil)
}
})
}
}

func getClient(query string) string {
startCommentIdx := strings.Index(query, "/*")
endCommentIdx := strings.Index(query, "*/")
if startCommentIdx < 0 || endCommentIdx < 0 {
panic("no client comment found in query " + query)
}

query = query[startCommentIdx+2 : endCommentIdx]
if strings.Index(query, "client ") < 0 {
panic("no client comment found in query " + query)
}

return strings.TrimSpace(strings.TrimPrefix(query, "client"))
}

// This method is the only place we can reliably test newly created views, because view definitions live in the
Expand Down Expand Up @@ -2843,7 +2861,11 @@ func RunQueryWithContext(t *testing.T, e *sqle.Engine, ctx *sql.Context, query s

// 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)
AssertErrWithCtx(t, e, NewContext(harness), query, expectedErrKind, errStrs...)
}

// AssertErrWithCtx is the same as AssertErr, but uses the context given instead of creating one from a harness
func AssertErrWithCtx(t *testing.T, e *sqle.Engine, ctx *sql.Context, query string, expectedErrKind *errors.Kind, errStrs ...string) {
_, iter, err := e.Query(ctx, query)
if err == nil {
_, err = sql.RowIterToRows(ctx, iter)
Expand Down
2 changes: 1 addition & 1 deletion enginetest/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ var ScriptTests = []ScriptTest{
dcim_rackgroup.level
FROM dcim_rackgroup
order by 2 limit 1`,
Expected: []sql.Row{{1, "5c107f979f434bf7a7820622f18a5211", sql.JSONDocument{Val:map[string]interface {}{}}, "Parent Rack Group 1", "parent-rack-group-1", "f0471f313b694d388c8ec39d9590e396", interface {}(nil), "", uint64(1), uint64(2), uint64(1), uint64(0)}},
Expected: []sql.Row{{1, "5c107f979f434bf7a7820622f18a5211", sql.JSONDocument{Val: map[string]interface{}{}}, "Parent Rack Group 1", "parent-rack-group-1", "f0471f313b694d388c8ec39d9590e396", interface{}(nil), "", uint64(1), uint64(2), uint64(1), uint64(0)}},
},
},
},
Expand Down
Loading