Skip to content

Commit

Permalink
move state to it's own package, and refactore the code to remove dupl…
Browse files Browse the repository at this point in the history
…ication

Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Oct 9, 2024
1 parent 47e1ee0 commit 8d70d85
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 350 deletions.
20 changes: 11 additions & 9 deletions go/tester/comparing_query_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ package tester

import (
"fmt"

log "github.com/sirupsen/logrus"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/utils"
"vitess.io/vitess/go/vt/sqlparser"

"github.com/vitessio/vitess-tester/go/data"
"github.com/vitessio/vitess-tester/go/tester/state"
)

type (
Expand Down Expand Up @@ -58,11 +60,11 @@ func newComparingQueryRunner(
}
}

func (nqr ComparingQueryRunner) runQuery(q data.Query, ast sqlparser.Statement, state *State) error {
func (nqr ComparingQueryRunner) runQuery(q data.Query, ast sqlparser.Statement, state *state.State) error {
return nqr.execute(q, ast, state)
}

func (nqr *ComparingQueryRunner) execute(query data.Query, ast sqlparser.Statement, state *State) error {
func (nqr *ComparingQueryRunner) execute(query data.Query, ast sqlparser.Statement, state *state.State) error {
if len(query.Query) == 0 {
return nil
}
Expand All @@ -74,15 +76,15 @@ func (nqr *ComparingQueryRunner) execute(query data.Query, ast sqlparser.Stateme
return nil
}

func (nqr *ComparingQueryRunner) executeStmt(query string, ast sqlparser.Statement, state *State) (err error) {
func (nqr *ComparingQueryRunner) executeStmt(query string, ast sqlparser.Statement, state *state.State) (err error) {
_, commentOnly := ast.(*sqlparser.CommentOnly)
if commentOnly {
return nil
}

log.Debugf("executeStmt: %s", query)
create, isCreateStatement := ast.(*sqlparser.CreateTable)
if isCreateStatement && !state.isErrorExpectedSet() && state.runOnVitess() {
if isCreateStatement && !state.IsErrorExpectedSet() && state.RunOnVitess() {
closer := nqr.handleCreateTable(create)
defer func() {
if err == nil {
Expand All @@ -92,21 +94,21 @@ func (nqr *ComparingQueryRunner) executeStmt(query string, ast sqlparser.Stateme
}

switch {
case state.checkAndClearErrorExpected():
case state.CheckAndClearErrorExpected():
err := nqr.execAndExpectErr(query)
if err != nil {
nqr.reporter.AddFailure(err)
}
default:
var err error
switch {
case state.checkAndClearReference():
case state.CheckAndClearReference():
return nqr.executeReference(query, ast)
case state.normalExecution():
case state.NormalExecution():
nqr.comparer.Exec(query)
case state.isVitessOnlySet():
case state.IsVitessOnlySet():
_, err = nqr.comparer.VtConn.ExecuteFetch(query, 1000, true)
case state.isMySQLOnlySet():
case state.IsMySQLOnlySet():
_, err = nqr.comparer.MySQLConn.ExecuteFetch(query, 1000, true)
}
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion go/tester/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ package tester

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGenerateShardRanges(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go/tester/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package tester

import (
"github.com/fatih/color"
"io"
"net/http"
"os"
"time"

"github.com/fatih/color"
log "github.com/sirupsen/logrus"
"vitess.io/vitess/go/test/endtoend/cluster"
)
Expand Down
203 changes: 0 additions & 203 deletions go/tester/state.go

This file was deleted.

Loading

0 comments on commit 8d70d85

Please sign in to comment.