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

*: avoid tidb-server -h output test flags #11209

Merged
merged 4 commits into from Jul 12, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -12,14 +12,14 @@ 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
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
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
Expand Up @@ -297,6 +297,36 @@ func GetRows4Test(ctx context.Context, sctx sessionctx.Context, rs sqlexec.Recor
return rows, nil
}

// 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
}

var (
errForUpdateCantRetry = terror.ClassSession.New(codeForUpdateCantRetry,
mysql.MySQLErrName[mysql.ErrForUpdateCantRetry])
Expand Down
2 changes: 2 additions & 0 deletions util/testkit/ctestkit.go
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
@@ -0,0 +1,3 @@
// +build codes

package testkit
34 changes: 3 additions & 31 deletions util/testkit/testkit.go
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 @@ -241,39 +243,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
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