Skip to content

Commit

Permalink
Use full path for test files
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Jun 19, 2024
1 parent eb95312 commit 57f88f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
33 changes: 3 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
"vitess.io/vitess/go/mysql"
Expand All @@ -37,7 +35,6 @@ var (
olap bool
vschemaFile string
xunit bool
testDir string
)

func init() {
Expand All @@ -46,33 +43,12 @@ func init() {
flag.BoolVar(&sharded, "sharded", false, "run all tests on a sharded keyspace")
flag.StringVar(&vschemaFile, "vschema", "", "Disable auto-vschema by providing your own vschema file")
flag.BoolVar(&xunit, "xunit", false, "Get output in an xml file instead of errors directory")
flag.StringVar(&testDir, "test-dir", "./t/", "Directory for the test files")
}

func loadAllTests() (tests []string, err error) {
// tests must be in t folder or subdir in t folder
err = filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if !info.IsDir() && strings.HasSuffix(path, ".test") {
name := strings.TrimSuffix(info.Name(), ".test")
tests = append(tests, name)
}
return nil
})

if err != nil {
return nil, err
}
return tests, nil
}

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 := vitess_tester.NewTester(name, errReporter, clusterInstance, vtParams, mysqlParams, olap, keyspaceName, vschema, testDir, vschemaFile)
vTester := vitess_tester.NewTester(name, errReporter, clusterInstance, vtParams, mysqlParams, olap, keyspaceName, vschema, vschemaFile)
err := vTester.Run()
if err != nil {
failed = true
Expand Down Expand Up @@ -240,12 +216,9 @@ func main() {
log.SetLevel(ll)
}

// we will run all tests if no tests assigned
if len(tests) == 0 {
var err error
if tests, err = loadAllTests(); err != nil {
log.Fatalf("load all tests err %v", err)
}
log.Errorf("no tests specified")
os.Exit(1)
}

log.Infof("running tests: %v", tests)
Expand Down
16 changes: 5 additions & 11 deletions src/vitess-tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
)

type tester struct {
dir string
name string

clusterInstance *cluster.LocalProcessCluster
Expand All @@ -59,14 +58,14 @@ type tester struct {
reporter Reporter
}

func NewTester(name string, reporter Reporter,
func NewTester(
name string,
reporter Reporter,
clusterInstance *cluster.LocalProcessCluster,
vtParams,
mysqlParams mysql.ConnParams,
vtParams, mysqlParams mysql.ConnParams,
olap bool,
keyspaceName string,
vschema vindexes.VSchema,
dir string,
vschemaFile string,
) *tester {
t := &tester{
Expand All @@ -78,7 +77,6 @@ func NewTester(name string, reporter Reporter,
keyspaceName: keyspaceName,
vschema: vschema,
vschemaFile: vschemaFile,
dir: dir,
olap: olap,
}
return t
Expand Down Expand Up @@ -275,7 +273,7 @@ func (t *tester) readData() ([]byte, error) {
defer res.Body.Close()
return io.ReadAll(res.Body)
}
return os.ReadFile(t.testFileName())
return os.ReadFile(t.name)
}

func (t *tester) execute(query query) error {
Expand Down Expand Up @@ -402,10 +400,6 @@ func (t *tester) handleCreateTable(create *sqlparser.CreateTable) {
}
}

func (t *tester) testFileName() string {
return fmt.Sprintf("%s/%s.test", t.dir, t.name)
}

func (t *tester) Errorf(format string, args ...interface{}) {
t.reporter.AddFailure(t.vschema, errors.Errorf(format, args...))
}
Expand Down

0 comments on commit 57f88f6

Please sign in to comment.