Skip to content

Commit

Permalink
fix pingcap#28164: adapt testify for backup
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen committed Oct 25, 2021
1 parent 51ce0dd commit 86389c7
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions br/pkg/task/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,54 @@ import (
"testing"
"time"

. "github.com/pingcap/check"
backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/stretchr/testify/require"
)

var _ = Suite(&testBackupSuite{})

func TestT(t *testing.T) {
TestingT(t)
}

type testBackupSuite struct{}

func (s *testBackupSuite) TestParseTSString(c *C) {
func TestParseTSString(t *testing.T) {
t.Parallel()
var (
ts uint64
err error
)

ts, err = parseTSString("")
c.Assert(err, IsNil)
c.Assert(int(ts), Equals, 0)
require.NoError(t, err)
require.Equal(t, int(ts), 0)

ts, err = parseTSString("400036290571534337")
c.Assert(err, IsNil)
c.Assert(int(ts), Equals, 400036290571534337)
require.NoError(t, err)
require.Equal(t, int(ts), 400036290571534337)

_, offset := time.Now().Local().Zone()
ts, err = parseTSString("2018-05-11 01:42:23")
c.Assert(err, IsNil)
c.Assert(int(ts), Equals, 400032515489792000-(offset*1000)<<18)
require.NoError(t, err)
require.Equal(t, int(ts), 400032515489792000-(offset*1000)<<18)
}

func (s *testBackupSuite) TestParseCompressionType(c *C) {
var (
ct backuppb.CompressionType
err error
)
ct, err = parseCompressionType("lz4")
c.Assert(err, IsNil)
c.Assert(int(ct), Equals, 1)

ct, err = parseCompressionType("snappy")
c.Assert(err, IsNil)
c.Assert(int(ct), Equals, 2)

ct, err = parseCompressionType("zstd")
c.Assert(err, IsNil)
c.Assert(int(ct), Equals, 3)

ct, err = parseCompressionType("Other Compression (strings)")
c.Assert(err, ErrorMatches, "invalid compression.*")
c.Assert(int(ct), Equals, 0)
func TestParseCompressionType(t *testing.T) {
t.Parallel()
cases := []struct {
str string
algo backuppb.CompressionType
errMatch func(error)
}{
{"lz4", backuppb.CompressionType_LZ4, nil},
{"snappy", backuppb.CompressionType_SNAPPY, nil},
{"zstd", backuppb.CompressionType_ZSTD, nil},
{"Other Compression (strings)", backuppb.CompressionType_UNKNOWN, func(e error) {
require.Error(t, e)
require.Regexp(t, "invalid compression.*", e.Error())
}},
}

for _, c := range cases {
ct, err := parseCompressionType(c.str)
if c.errMatch == nil {
require.NoError(t, err)
} else {
c.errMatch(err)
}
require.Equal(t, c.algo, ct)
}
}

0 comments on commit 86389c7

Please sign in to comment.