Skip to content

Commit

Permalink
*: avoid tidb-server -h output test flags (#11209) (#16164)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored Apr 8, 2020
1 parent 77548e9 commit 534262c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH))):$(PWD)/tools/bin
export PATH := $(path_to_add):$(PATH)

GO := GO111MODULE=on go
GOBUILD := CGO_ENABLED=1 $(GO) build $(BUILD_FLAG)
GOBUILD := CGO_ENABLED=1 $(GO) build $(BUILD_FLAG) -tags codes
GOBUILDCOVERAGE := GOPATH=$(GOPATH) CGO_ENABLED=1 cd tidb-server; $(GO) test -coverpkg="../..." -c .
GOTEST := CGO_ENABLED=1 $(GO) test -p 4
OVERALLS := CGO_ENABLED=1 GO111MODULE=on overalls

ARCH := "`uname -s`"
LINUX := "Linux"
MAC := "Darwin"
PACKAGE_LIST := go list ./...| grep -vE "cmd"
PACKAGE_LIST := go list ./...| grep -vE "cmd" | grep -vE "test"
PACKAGES := $$($(PACKAGE_LIST))
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/$(PROJECT)/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")
Expand Down
7 changes: 3 additions & 4 deletions server/sql_info_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/pingcap/tidb/statistics/handle"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/testkit"
)

type sqlInfoFetcher struct {
Expand Down Expand Up @@ -171,7 +170,7 @@ func (sh *sqlInfoFetcher) zipInfoForSQL(w http.ResponseWriter, r *http.Request)
terror.Log(err)
return
}
sRows, err := testkit.ResultSetToStringSlice(reqCtx, sh.s, recordSets[0])
sRows, err := session.ResultSetToStringSlice(reqCtx, sh.s, recordSets[0])
if err != nil {
err = sh.writeErrFile(zw, "explain.err.txt", err)
terror.Log(err)
Expand Down Expand Up @@ -248,7 +247,7 @@ func (sh *sqlInfoFetcher) getExplainAnalyze(ctx context.Context, sql string, res
resultChan <- &explainAnalyzeResult{err: err}
return
}
rows, err := testkit.ResultSetToStringSlice(ctx, sh.s, recordSets[0])
rows, err := session.ResultSetToStringSlice(ctx, sh.s, recordSets[0])
if err != nil {
terror.Log(err)
rows = nil
Expand Down Expand Up @@ -292,7 +291,7 @@ func (sh *sqlInfoFetcher) getShowCreateTable(pair tableNamePair, zw *zip.Writer)
if err != nil {
return err
}
sRows, err := testkit.ResultSetToStringSlice(context.Background(), sh.s, recordSets[0])
sRows, err := session.ResultSetToStringSlice(context.Background(), sh.s, recordSets[0])
if err != nil {
terror.Log(err)
return nil
Expand Down
30 changes: 30 additions & 0 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,36 @@ func IsQuery(sql string) bool {
return false
}

// ResultSetToStringSlice changes the RecordSet to [][]string.
func ResultSetToStringSlice(ctx context.Context, s Session, rs sqlexec.RecordSet) ([][]string, error) {
rows, err := GetRows4Test(ctx, s, rs)
if err != nil {
return nil, err
}
err = rs.Close()
if err != nil {
return nil, err
}
sRows := make([][]string, len(rows))
for i := range rows {
row := rows[i]
iRow := make([]string, row.Len())
for j := 0; j < row.Len(); j++ {
if row.IsNull(j) {
iRow[j] = "<nil>"
} else {
d := row.GetDatum(j, &rs.Fields()[j].Column.FieldType)
iRow[j], err = d.ToString()
if err != nil {
return nil, err
}
}
}
sRows[i] = iRow
}
return sRows, nil
}

// Session errors.
var (
ErrForUpdateCantRetry = terror.ClassSession.New(codeForUpdateCantRetry,
Expand Down
2 changes: 2 additions & 0 deletions util/testkit/ctestkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !codes

package testkit

import (
Expand Down
3 changes: 3 additions & 0 deletions util/testkit/fake.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// +build codes

package testkit
34 changes: 3 additions & 31 deletions util/testkit/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !codes

package testkit

import (
Expand Down Expand Up @@ -269,39 +271,9 @@ func (tk *TestKit) ResultSetToResult(rs sqlexec.RecordSet, comment check.Comment
return tk.ResultSetToResultWithCtx(context.Background(), rs, comment)
}

// ResultSetToStringSlice changes the RecordSet to [][]string.
func ResultSetToStringSlice(ctx context.Context, s session.Session, rs sqlexec.RecordSet) ([][]string, error) {
rows, err := session.GetRows4Test(ctx, s, rs)
if err != nil {
return nil, err
}
err = rs.Close()
if err != nil {
return nil, err
}
sRows := make([][]string, len(rows))
for i := range rows {
row := rows[i]
iRow := make([]string, row.Len())
for j := 0; j < row.Len(); j++ {
if row.IsNull(j) {
iRow[j] = "<nil>"
} else {
d := row.GetDatum(j, &rs.Fields()[j].Column.FieldType)
iRow[j], err = d.ToString()
if err != nil {
return nil, err
}
}
}
sRows[i] = iRow
}
return sRows, nil
}

// ResultSetToResultWithCtx converts sqlexec.RecordSet to testkit.Result.
func (tk *TestKit) ResultSetToResultWithCtx(ctx context.Context, rs sqlexec.RecordSet, comment check.CommentInterface) *Result {
sRows, err := ResultSetToStringSlice(ctx, tk.Se, rs)
sRows, err := session.ResultSetToStringSlice(ctx, tk.Se, rs)
tk.c.Check(err, check.IsNil, comment)
return &Result{rows: sRows, c: tk.c, comment: comment}
}
Expand Down
2 changes: 2 additions & 0 deletions util/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !codes

package testutil

import (
Expand Down

0 comments on commit 534262c

Please sign in to comment.