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 mysql-tester less verbose/confusing #46

Closed
wants to merge 5 commits into from
Closed
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
30 changes: 20 additions & 10 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (t *tester) preProcess() {
log.Fatalf("Open db err %v", err)
}

log.Warn("Create new db", mdb)
log.Debug("Create new db", mdb)

if _, err = mdb.Exec(fmt.Sprintf("create database `%s`", t.name)); err != nil {
log.Fatalf("Executing create db %s err[%v]", t.name, err)
Expand Down Expand Up @@ -538,12 +538,8 @@ func (t *tester) concurrentExecute(querys []query, wg *sync.WaitGroup, errOccure
}
return
}
func (t *tester) loadQueries() ([]query, error) {
data, err := ioutil.ReadFile(t.testFileName())
if err != nil {
return nil, err
}

func parseQueryLines(data []byte) []query {
seps := bytes.Split(data, []byte("\n"))
queries := make([]query, 0, len(seps))
newStmt := true
Expand Down Expand Up @@ -573,7 +569,16 @@ func (t *tester) loadQueries() ([]query, error) {
// if the line has a ; in the end, we will treat new line as the new statement.
newStmt = strings.HasSuffix(s, ";")
}
return queries
}

func (t *tester) loadQueries() ([]query, error) {
data, err := ioutil.ReadFile(t.testFileName())
if err != nil {
return nil, err
}

queries := parseQueryLines(data)
return ParseQueries(queries...)
}

Expand Down Expand Up @@ -1072,26 +1077,31 @@ func consumeError() []error {
func main() {
flag.Parse()
tests := flag.Args()
intLogLevel, err := log.ParseLevel(logLevel)
if err != nil {
log.Fatal(err)
}
log.SetLevel(intLogLevel)
startTime := time.Now()

if xmlPath != "" {
_, err := os.Stat(xmlPath)
if err == nil {
err = os.Remove(xmlPath)
if err != nil {
log.Errorf("drop previous xunit file fail: ", err)
log.Errorf("drop previous xunit file fail: %v", err)
os.Exit(1)
}
}

xmlFile, err = os.Create(xmlPath)
if err != nil {
log.Errorf("create xunit file fail:", err)
log.Errorf("create xunit file fail: %v", err)
os.Exit(1)
}
xmlFile, err = os.OpenFile(xmlPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
log.Errorf("open xunit file fail:", err)
log.Errorf("open xunit file fail: %v", err)
os.Exit(1)
}

Expand All @@ -1113,7 +1123,7 @@ func main() {
})
err := Write(xmlFile, testSuite)
if err != nil {
log.Errorf("Write xunit file fail:", err)
log.Errorf("Write xunit file fail: %v", err)
}
}
}()
Expand Down
14 changes: 7 additions & 7 deletions src/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ func assertEqual(t *testing.T, a interface{}, b interface{}, message string) {
}

func TestParseQueryies(t *testing.T) {
query := "select * from t;"
if q, err := ParseQueries(query); err == nil {
query := []byte("select * from t;")
if q, err := ParseQueries(parseQueryLines(query)...); err == nil {
assertEqual(t, q[0].tp, Q_QUERY, fmt.Sprintf("Expected: %d, got: %d", Q_QUERY, q[0].tp))
assertEqual(t, q[0].Query, query, fmt.Sprintf("Expected: %s, got: %s", query, q[0].Query))
assertEqual(t, q[0].Query, string(query), fmt.Sprintf("Expected: %s, got: %s", query, q[0].Query))
} else {
t.Fatalf("error is not nil. %v", err)
}

query = "--sorted_result select * from t;"
if q, err := ParseQueries(query); err == nil {
query = []byte("--sorted_result select * from t;")
if q, err := ParseQueries(parseQueryLines(query)...); err == nil {
assertEqual(t, q[0].tp, Q_SORTED_RESULT, "sorted_result")
assertEqual(t, q[0].Query, "select * from t;", fmt.Sprintf("Expected: '%s', got '%s'", "select * from t;", q[0].Query))
} else {
t.Fatalf("error is not nil. %s", err)
}

// invalid comment command style
query = "--abc select * from t;"
_, err := ParseQueries(query)
query = []byte("--abc select * from t;")
_, err := ParseQueries(parseQueryLines(query)...)
assertEqual(t, err, ErrInvalidCommand, fmt.Sprintf("Expected: %v, got %v", ErrInvalidCommand, err))

}
2 changes: 1 addition & 1 deletion src/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Write(out io.Writer, testSuite XUnitTestSuite) error {
testSuites.Suites = append(testSuites.Suites, testSuite)
_, err := out.Write([]byte(xml.Header))
if err != nil {
log.Errorf("write xunit file fail:", err)
log.Errorf("write xunit file fail: %v", err)
return err
}
doc, err := xml.MarshalIndent(testSuites, "", "\t")
Expand Down