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

br/pkg/storage: migrate test-infra to testify #31026

Merged
merged 2 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
25 changes: 13 additions & 12 deletions br/pkg/storage/compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@ import (
"os"
"path/filepath"
"strings"
"testing"

. "github.com/pingcap/check"
"github.com/stretchr/testify/require"
)

func (r *testStorageSuite) TestWithCompressReadWriteFile(c *C) {
dir := c.MkDir()
func TestWithCompressReadWriteFile(t *testing.T) {
dir := t.TempDir()
backend, err := ParseBackend("local://"+filepath.ToSlash(dir), nil)
c.Assert(err, IsNil)
require.NoError(t, err)
ctx := context.Background()
storage, err := Create(ctx, backend, true)
c.Assert(err, IsNil)
require.NoError(t, err)
storage = WithCompression(storage, Gzip)
name := "with compress test"
content := "hello,world!"
fileName := strings.ReplaceAll(name, " ", "-") + ".txt.gz"
err = storage.WriteFile(ctx, fileName, []byte(content))
c.Assert(err, IsNil)
require.NoError(t, err)

// make sure compressed file is written correctly
file, err := os.Open(filepath.Join(dir, fileName))
c.Assert(err, IsNil)
require.NoError(t, err)
uncompressedFile, err := newCompressReader(Gzip, file)
c.Assert(err, IsNil)
require.NoError(t, err)
newContent, err := io.ReadAll(uncompressedFile)
c.Assert(err, IsNil)
c.Assert(string(newContent), Equals, content)
require.NoError(t, err)
require.Equal(t, content, string(newContent))

// test withCompression ReadFile
newContent, err = storage.ReadFile(ctx, fileName)
c.Assert(err, IsNil)
c.Assert(string(newContent), Equals, content)
require.NoError(t, err)
require.Equal(t, content, string(newContent))
}
Loading