diff --git a/Makefile b/Makefile index e82bbe91a31fa..6eeaac07973a0 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ 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 @@ -20,7 +20,7 @@ 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") diff --git a/server/sql_info_fetcher.go b/server/sql_info_fetcher.go index 8f07a340c13d6..204233d8acd42 100644 --- a/server/sql_info_fetcher.go +++ b/server/sql_info_fetcher.go @@ -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 { @@ -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) @@ -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 @@ -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 diff --git a/session/tidb.go b/session/tidb.go index 568edddb240c5..4498848fa8ad2 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -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] = "" + } 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, diff --git a/util/testkit/ctestkit.go b/util/testkit/ctestkit.go index 726a15c94428a..f3bb5e75d6232 100644 --- a/util/testkit/ctestkit.go +++ b/util/testkit/ctestkit.go @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build !codes + package testkit import ( diff --git a/util/testkit/fake.go b/util/testkit/fake.go new file mode 100644 index 0000000000000..20321b82ae7d9 --- /dev/null +++ b/util/testkit/fake.go @@ -0,0 +1,3 @@ +// +build codes + +package testkit diff --git a/util/testkit/testkit.go b/util/testkit/testkit.go index 04e1df79b5796..a02463450180b 100644 --- a/util/testkit/testkit.go +++ b/util/testkit/testkit.go @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build !codes + package testkit import ( @@ -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] = "" - } 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} } diff --git a/util/testutil/testutil.go b/util/testutil/testutil.go index 9e4928c6df696..3aee8a4146613 100644 --- a/util/testutil/testutil.go +++ b/util/testutil/testutil.go @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build !codes + package testutil import (