github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/task/backup_test.go (about)

     1  // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
     2  
     3  package task
     4  
     5  import (
     6  	"testing"
     7  	"time"
     8  
     9  	. "github.com/pingcap/check"
    10  	backuppb "github.com/pingcap/kvproto/pkg/backup"
    11  )
    12  
    13  var _ = Suite(&testBackupSuite{})
    14  
    15  func TestT(t *testing.T) {
    16  	TestingT(t)
    17  }
    18  
    19  type testBackupSuite struct{}
    20  
    21  func (s *testBackupSuite) TestParseTSString(c *C) {
    22  	var (
    23  		ts  uint64
    24  		err error
    25  	)
    26  
    27  	ts, err = parseTSString("")
    28  	c.Assert(err, IsNil)
    29  	c.Assert(int(ts), Equals, 0)
    30  
    31  	ts, err = parseTSString("400036290571534337")
    32  	c.Assert(err, IsNil)
    33  	c.Assert(int(ts), Equals, 400036290571534337)
    34  
    35  	_, offset := time.Now().Local().Zone()
    36  	ts, err = parseTSString("2018-05-11 01:42:23")
    37  	c.Assert(err, IsNil)
    38  	c.Assert(int(ts), Equals, 400032515489792000-(offset*1000)<<18)
    39  }
    40  
    41  func (s *testBackupSuite) TestParseCompressionType(c *C) {
    42  	var (
    43  		ct  backuppb.CompressionType
    44  		err error
    45  	)
    46  	ct, err = parseCompressionType("lz4")
    47  	c.Assert(err, IsNil)
    48  	c.Assert(int(ct), Equals, 1)
    49  
    50  	ct, err = parseCompressionType("snappy")
    51  	c.Assert(err, IsNil)
    52  	c.Assert(int(ct), Equals, 2)
    53  
    54  	ct, err = parseCompressionType("zstd")
    55  	c.Assert(err, IsNil)
    56  	c.Assert(int(ct), Equals, 3)
    57  
    58  	ct, err = parseCompressionType("Other Compression (strings)")
    59  	c.Assert(err, ErrorMatches, "invalid compression.*")
    60  	c.Assert(int(ct), Equals, 0)
    61  }