Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

test: refine and improve pkg/utils unit test coverage to 82.3% #1054

Merged
merged 26 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
319b2eb
*: move and refine UT for `TrimCtrlChars`
csuzhangxc Sep 17, 2020
eb86c9c
*: temp find out coverage
csuzhangxc Sep 17, 2020
64ac701
Update Makefile
csuzhangxc Sep 17, 2020
efc5068
*: fix makefile
csuzhangxc Sep 17, 2020
2bae392
makefile: goveralls may fail, so put it later
csuzhangxc Sep 17, 2020
6e714f4
utils: add test cases for `FetchAllDoTables` and refine code
csuzhangxc Sep 17, 2020
f8f3055
Merge branch 'master' into ut-cov-util
csuzhangxc Sep 21, 2020
33de239
*: add more test cases for common.go
csuzhangxc Sep 21, 2020
3000a86
*: more test cases for common.go
csuzhangxc Sep 21, 2020
fd587e1
*: add some test cases for db.go
csuzhangxc Sep 21, 2020
6a2974e
*: more test cases for db.go
csuzhangxc Sep 22, 2020
6b2ff9b
Merge branch 'master' into ut-cov-util
csuzhangxc Sep 22, 2020
063c3d3
*: refine MySQL error usage
csuzhangxc Sep 22, 2020
35511cb
*: fix ErrBadConn
csuzhangxc Sep 22, 2020
f3da7de
*: add test case for encrypt.go
csuzhangxc Sep 22, 2020
a24f7b6
*: fix ErrBadConn
csuzhangxc Sep 22, 2020
6889973
*: add test cases for file.go
csuzhangxc Sep 22, 2020
5e3916a
*: add test case for hash.go
csuzhangxc Sep 22, 2020
fc0d506
*: add test cases for printer.go
csuzhangxc Sep 22, 2020
d0b036b
*: add test case for GenFakeRotateEvent
csuzhangxc Sep 22, 2020
1689715
*: add test case for storage.go
csuzhangxc Sep 22, 2020
06eb7a0
*: move JoinProcessErrors and add test case
csuzhangxc Sep 22, 2020
9578d5d
*: add test cases for util.go
csuzhangxc Sep 22, 2020
a9064bb
Merge branch 'master' into ut-cov-util
csuzhangxc Sep 23, 2020
54e8b05
*: address comments
csuzhangxc Sep 23, 2020
f63d05b
*: revert some cov exclude
csuzhangxc Sep 23, 2020
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ coverage_fix_cover_mode:
sed -i "s/mode: count/mode: atomic/g" $(TEST_DIR)/cov.*.dmctl.*.out

coverage: coverage_fix_cover_mode retool_setup
retool do gocovmerge "$(TEST_DIR)"/cov.* | grep -vE ".*.pb.go|.*.__failpoint_binding__.go" > "$(TEST_DIR)/all_cov.out"
retool do gocovmerge "$(TEST_DIR)"/cov.unit_test*.out | grep -vE ".*.pb.go|.*.__failpoint_binding__.go" > $(TEST_DIR)/unit_test.out
retool do gocovmerge "$(TEST_DIR)"/cov.* | grep -vE ".*.pb.go|.*.__failpoint_binding__.go|.*debug-tools.*|.*portal.*|.*tracer.*|.*loader.*|.*tracing.*|.*ctl.* > "$(TEST_DIR)/all_cov.out"
retool do gocovmerge "$(TEST_DIR)"/cov.unit_test*.out | grep -vE ".*.pb.go|.*.__failpoint_binding__.go|.*debug-tools.*|.*portal.*|.*tracer.*|.*loader .*|.*tracing.*|.*ctl.*" > $(TEST_DIR)/unit_test.out
csuzhangxc marked this conversation as resolved.
Show resolved Hide resolved
ifeq ("$(JenkinsCI)", "1")
@retool do goveralls -coverprofile=$(TEST_DIR)/all_cov.out -service=jenkins-ci -repotoken $(COVERALLS_TOKEN)
@bash <(curl -s https://codecov.io/bash) -f $(TEST_DIR)/unit_test.out -t $(CODECOV_TOKEN)
Expand Down
54 changes: 54 additions & 0 deletions pkg/utils/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import (
"bytes"

. "github.com/pingcap/check"
"github.com/pingcap/parser"
)

var _ = Suite(&testCommonSuite{})

type testCommonSuite struct {
}

func (s *testCommonSuite) TestTrimCtrlChars(c *C) {
ddl := "create table if not exists foo.bar(id int)"
controlChars := make([]byte, 0, 33)
nul := byte(0x00)
for i := 0; i < 32; i++ {
controlChars = append(controlChars, nul)
nul++
}
controlChars = append(controlChars, 0x7f)

parser2 := parser.New()
var buf bytes.Buffer
for _, char := range controlChars {
buf.WriteByte(char)
buf.WriteByte(char)
buf.WriteString(ddl)
buf.WriteByte(char)
buf.WriteByte(char)

newDDL := TrimCtrlChars(buf.String())
c.Assert(newDDL, Equals, ddl)

_, err := parser2.ParseOneStmt(newDDL, "", "")
c.Assert(err, IsNil)
buf.Reset()
}
}
34 changes: 0 additions & 34 deletions syncer/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package syncer

import (
"bytes"

"github.com/pingcap/dm/dm/config"
tcontext "github.com/pingcap/dm/pkg/context"
parserpkg "github.com/pingcap/dm/pkg/parser"
Expand All @@ -28,38 +26,6 @@ import (
router "github.com/pingcap/tidb-tools/pkg/table-router"
)

func (s *testSyncerSuite) TestTrimCtrlChars(c *C) {
ddl := "create table if not exists foo.bar(id int)"
controlChars := make([]byte, 0, 33)
nul := byte(0x00)
for i := 0; i < 32; i++ {
controlChars = append(controlChars, nul)
nul++
}
controlChars = append(controlChars, 0x7f)

var buf bytes.Buffer
db, mock, err := sqlmock.New()
c.Assert(err, IsNil)
p, err := s.mockParser(db, mock)
c.Assert(err, IsNil)

for _, char := range controlChars {
buf.WriteByte(char)
buf.WriteByte(char)
buf.WriteString(ddl)
buf.WriteByte(char)
buf.WriteByte(char)

newDDL := utils.TrimCtrlChars(buf.String())
c.Assert(len(newDDL), Equals, len(ddl))

_, err := p.ParseOneStmt(newDDL, "", "")
c.Assert(err, IsNil)
buf.Reset()
}
}

func (s *testSyncerSuite) TestAnsiQuotes(c *C) {
ansiQuotesCases := []string{
"create database `test`",
Expand Down