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

Make vitess-tester work with go install #6

Merged
merged 1 commit into from
Jun 12, 2024
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
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ GO := go
default: build

build:
$(GO) build -o vitess-tester ./src/vitess-tester

debug:
$(GO) build -gcflags="all=-N -l" -o vitess-tester ./src/vitess-tester
$(GO) build -o vitess-tester ./

test: build
$(GO) test -cover ./...
Expand All @@ -20,6 +17,3 @@ tidy:
clean:
$(GO) clean -i ./...
rm -rf vitess-tester

gen_perror: generate_perror/main.go
$(GO) build -o gen_perror ./generate_perror
35 changes: 13 additions & 22 deletions src/vitess-tester/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"vitess.io/vitess/go/test/endtoend/utils"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtgate/vindexes"

vitess_tester "github.com/vitessio/vitess-tester/src/vitess-tester"
)

var (
Expand All @@ -45,13 +47,6 @@ func init() {
flag.BoolVar(&xunit, "xunit", false, "Get output in an xml file instead of errors directory")
}

type query struct {
firstWord string
Query string
Line int
tp CmdType
}

func loadAllTests() (tests []string, err error) {
// tests must be in t folder or subdir in t folder
err = filepath.Walk("./t/", func(path string, info os.FileInfo, err error) error {
Expand All @@ -72,10 +67,10 @@ func loadAllTests() (tests []string, err error) {
return tests, nil
}

func executeTests(fileNames []string, s Suite) (failed bool) {
func executeTests(clusterInstance *cluster.LocalProcessCluster, vtParams, mysqlParams mysql.ConnParams, fileNames []string, s vitess_tester.Suite) (failed bool) {
for _, name := range fileNames {
errReporter := s.NewReporterForFile(name)
vTester := newTester(name, errReporter)
vTester := vitess_tester.NewTester(name, errReporter, clusterInstance, vtParams, mysqlParams, olap, keyspaceName, vschema, vschemaFile)
err := vTester.Run()
if err != nil {
failed = true
Expand All @@ -88,12 +83,8 @@ func executeTests(fileNames []string, s Suite) (failed bool) {
}

var (
clusterInstance *cluster.LocalProcessCluster
keyspaceName = "mysqltest"
cell = "mysqltest"

vtParams mysql.ConnParams
mysqlParams mysql.ConnParams
keyspaceName = "mysqltest"
cell = "mysqltest"
)

type rawKeyspaceVindex struct {
Expand Down Expand Up @@ -122,7 +113,7 @@ var vschema = vindexes.VSchema{
},
}

func setupCluster(sharded bool) func() {
func setupCluster(sharded bool) (clusterInstance *cluster.LocalProcessCluster, vtParams, mysqlParams mysql.ConnParams, close func()) {
clusterInstance = cluster.NewCluster(cell, "localhost")

// Start topo server
Expand Down Expand Up @@ -171,7 +162,7 @@ func setupCluster(sharded bool) func() {
}
mysqlParams = conn

return func() {
return clusterInstance, vtParams, mysqlParams, func() {
clusterInstance.Teardown()
closer()
}
Expand Down Expand Up @@ -257,7 +248,7 @@ func main() {

log.Infof("running tests: %v", tests)

closer := setupCluster(sharded)
clusterInstance, vtParams, mysqlParams, closer := setupCluster(sharded)
defer closer()

// remove errors folder if exists
Expand All @@ -266,13 +257,13 @@ func main() {
panic(err.Error())
}

var reporterSuite Suite
var reporterSuite vitess_tester.Suite
if xunit {
reporterSuite = newXMLTestSuite()
reporterSuite = vitess_tester.NewXMLTestSuite()
} else {
reporterSuite = newFileReporterSuite()
reporterSuite = vitess_tester.NewFileReporterSuite()
}
failed := executeTests(tests, reporterSuite)
failed := executeTests(clusterInstance, vtParams, mysqlParams, tests, reporterSuite)
outputFile := reporterSuite.Close()
if failed {
log.Errorf("some tests failed 😭\nsee errors in %v", outputFile)
Expand Down
9 changes: 8 additions & 1 deletion src/vitess-tester/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package vitess_tester

import (
"strings"
Expand Down Expand Up @@ -130,6 +130,13 @@ const (
Q_VEXPLAIN
)

type query struct {
firstWord string
Query string
Line int
tp CmdType
}

// ParseQueries parses an array of string into an array of query object.
// Note: a query statement may reside in several lines.
func ParseQueries(qs ...query) ([]query, error) {
Expand Down
2 changes: 1 addition & 1 deletion src/vitess-tester/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package vitess_tester

import (
"fmt"
Expand Down
14 changes: 8 additions & 6 deletions src/vitess-tester/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package main
package vitess_tester

import (
"encoding/json"
Expand All @@ -24,6 +24,8 @@ import (
"path"
"strings"
"time"

"vitess.io/vitess/go/vt/vtgate/vindexes"
)

type Suite interface {
Expand All @@ -35,7 +37,7 @@ type Suite interface {
type Reporter interface {
AddTestCase(query string, lineNo int)
EndTestCase()
AddFailure(err error)
AddFailure(vschema vindexes.VSchema, err error)
Report() string
Failed() bool
}
Expand All @@ -52,7 +54,7 @@ func (frs *FileReporterSuite) Close() string {
return "errors"
}

func newFileReporterSuite() *FileReporterSuite {
func NewFileReporterSuite() *FileReporterSuite {
return &FileReporterSuite{}
}

Expand Down Expand Up @@ -115,7 +117,7 @@ func (e *FileReporter) EndTestCase() {
}
}

func (e *FileReporter) AddFailure(err error) {
func (e *FileReporter) AddFailure(vschema vindexes.VSchema, err error) {
e.failureCount++
e.currentQueryFailed = true
if e.currentQuery == "" {
Expand All @@ -130,7 +132,7 @@ func (e *FileReporter) AddFailure(err error) {
panic("failed to write error file\n" + err.Error())
}

e.createVSchemaDump()
e.createVSchemaDump(vschema)
}

func (e *FileReporter) createErrorFileFor() *os.File {
Expand All @@ -152,7 +154,7 @@ func (e *FileReporter) createErrorFileFor() *os.File {
return file
}

func (e *FileReporter) createVSchemaDump() {
func (e *FileReporter) createVSchemaDump(vschema vindexes.VSchema) {
errorDir := e.errorDir()
err := os.MkdirAll(errorDir, PERM)
if err != nil {
Expand Down
Loading
Loading