Skip to content

Commit

Permalink
Merge branch 'master' of github.com:yibin87/tidb
Browse files Browse the repository at this point in the history
  • Loading branch information
yibin87 committed Feb 23, 2022
2 parents d40ad26 + 55f0309 commit 274dd57
Show file tree
Hide file tree
Showing 36 changed files with 1,127 additions and 601 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ fix.sql
export-20*/
*-coverage.xml
*-junit-report.xml
# Files generated when testing
out
29 changes: 14 additions & 15 deletions br/pkg/lightning/config/bytesize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ package config_test

import (
"encoding/json"
"fmt"
"strings"
"testing"

"github.com/BurntSushi/toml"
. "github.com/pingcap/check"
"github.com/pingcap/tidb/br/pkg/lightning/config"
"github.com/stretchr/testify/require"
)

type byteSizeTestSuite struct{}

var _ = Suite(&byteSizeTestSuite{})

func (s *byteSizeTestSuite) TestByteSizeTOMLDecode(c *C) {
func TestByteSizeTOMLDecode(t *testing.T) {
testCases := []struct {
input string
output config.ByteSize
Expand Down Expand Up @@ -100,30 +98,31 @@ func (s *byteSizeTestSuite) TestByteSizeTOMLDecode(c *C) {
}

for _, tc := range testCases {
comment := Commentf("input: `%s`", tc.input)
comment := fmt.Sprintf("input: `%s`", tc.input)
var output struct{ X config.ByteSize }
err := toml.Unmarshal([]byte(tc.input), &output)
if tc.err != "" {
c.Assert(err, ErrorMatches, tc.err, comment)
require.Error(t, err)
require.Regexp(t, tc.err, err.Error(), comment)
} else {
c.Assert(err, IsNil, comment)
c.Assert(output.X, Equals, tc.output, comment)
require.NoError(t, err)
require.Equal(t, tc.output, output.X, comment)
}
}
}

func (s *byteSizeTestSuite) TestByteSizeTOMLAndJSONEncode(c *C) {
func TestByteSizeTOMLAndJSONEncode(t *testing.T) {
var input struct {
X config.ByteSize `toml:"x" json:"x"`
}
input.X = 1048576

var output strings.Builder
err := toml.NewEncoder(&output).Encode(input)
c.Assert(err, IsNil)
c.Assert(output.String(), Equals, "x = 1048576\n")
require.NoError(t, err)
require.Equal(t, "x = 1048576\n", output.String())

js, err := json.Marshal(input)
c.Assert(err, IsNil)
c.Assert(string(js), Equals, `{"x":1048576}`)
require.NoError(t, err)
require.Equal(t, `{"x":1048576}`, string(js))
}
Loading

0 comments on commit 274dd57

Please sign in to comment.