Skip to content

Commit

Permalink
Style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Catmoonlight committed Feb 20, 2023
1 parent 695939e commit deeefb2
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 93 deletions.
11 changes: 5 additions & 6 deletions cmd/pg/backup_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package pg
import (
"fmt"

"github.com/wal-g/wal-g/internal/databases/postgres"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wal-g/tracelog"
"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/internal/databases/postgres"
"github.com/wal-g/wal-g/pkg/storages/storage"
)

Expand All @@ -21,10 +20,10 @@ For information about pattern syntax view: https://golang.org/pkg/path/filepath/
reverseDeltaUnpackDescription = "Unpack delta backups in reverse order (beta feature)"
skipRedundantTarsDescription = "Skip tars with no useful data (requires reverse delta unpack)"
targetUserDataDescription = "Fetch storage backup which has the specified user data"
skipDirectoryCheckDescription = `Skip emptiness check & skip download of all existed files. Requires reverse delta unpack!
Use with --skip-redundant-tars option. Unsafe if tablespaces specified.`
onlyDatabasesDescription = `Downloads databases specified by passed db ids from default tablespace. Requires reverse delta unpack!
Use with --skip-redundant-tars option for partial backup`
skipDirectoryCheckDescription = `Skip emptiness check & skip download of all existed files.
Requires reverse delta unpack! Use with --skip-redundant-tars option. Unsafe if tablespaces specified.`
onlyDatabasesDescription = `Downloads databases specified by passed db ids from default tablespace.
Requires reverse delta unpack! Use with --skip-redundant-tars option for partial backup`
)

var fileMask string
Expand Down
30 changes: 15 additions & 15 deletions internal/databases/greenplum/backup_fetch_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@ import (

func TestPrepareContentIDsToFetch(t *testing.T) {
testcases := []struct {
fetchContentId []int
segmentConfig []cluster.SegConfig
fetchContentId []int
segmentConfig []cluster.SegConfig
contentIDsToFetch map[int]bool
} {
}{
{
fetchContentId: []int{},
segmentConfig: []cluster.SegConfig{},
fetchContentId: []int{},
segmentConfig: []cluster.SegConfig{},
contentIDsToFetch: map[int]bool{},
},
{
fetchContentId: []int{},
segmentConfig: []cluster.SegConfig{{ContentID: 21}, {ContentID: 42}},
fetchContentId: []int{},
segmentConfig: []cluster.SegConfig{{ContentID: 21}, {ContentID: 42}},
contentIDsToFetch: map[int]bool{21: true, 42: true},
},
{
fetchContentId: []int{1},
segmentConfig: []cluster.SegConfig{{ContentID: 1231}, {ContentID: 6743}, {ContentID: 7643}},
fetchContentId: []int{1},
segmentConfig: []cluster.SegConfig{{ContentID: 1231}, {ContentID: 6743}, {ContentID: 7643}},
contentIDsToFetch: map[int]bool{1: true},
},
{
fetchContentId: []int{65, 42, 12, 76, 22},
segmentConfig: []cluster.SegConfig{},
fetchContentId: []int{65, 42, 12, 76, 22},
segmentConfig: []cluster.SegConfig{},
contentIDsToFetch: map[int]bool{65: true, 42: true, 12: true, 76: true, 22: true},
},
{
fetchContentId: []int{5, 4, 3, 2, 1},
segmentConfig: []cluster.SegConfig{{ContentID: 4}, {ContentID: 5}, {ContentID: 6}},
fetchContentId: []int{5, 4, 3, 2, 1},
segmentConfig: []cluster.SegConfig{{ContentID: 4}, {ContentID: 5}, {ContentID: 6}},
contentIDsToFetch: map[int]bool{1: true, 2: true, 3: true, 4: true, 5: true},
},
{
fetchContentId: []int{6, 7, 8, 9, 10},
segmentConfig: []cluster.SegConfig{{ContentID: 1}, {ContentID: 5}, {ContentID: 7}},
fetchContentId: []int{6, 7, 8, 9, 10},
segmentConfig: []cluster.SegConfig{{ContentID: 1}, {ContentID: 5}, {ContentID: 7}},
contentIDsToFetch: map[int]bool{6: true, 7: true, 8: true, 9: true, 10: true},
},
}
Expand Down
9 changes: 5 additions & 4 deletions internal/databases/postgres/backup_fetch_handler_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package postgres

import (
"fmt"
"github.com/wal-g/tracelog"
"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/pkg/storages/storage"
"github.com/wal-g/wal-g/utility"
"io/fs"
"path"
"path/filepath"
"strconv"
"strings"

"github.com/wal-g/tracelog"
"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/pkg/storages/storage"
"github.com/wal-g/wal-g/utility"
)

func GetPgFetcherNew(dbDataDirectory, fileMask, restoreSpecPath string, skipRedundantTars bool,
Expand Down
12 changes: 6 additions & 6 deletions internal/databases/postgres/dir_database_tar_ball_composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package postgres

import (
"archive/tar"
"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/internal/crypto"
"golang.org/x/sync/errgroup"
"os"
"path"
"strings"

"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/internal/crypto"
"golang.org/x/sync/errgroup"
)

type DirDatabaseTarBallComposerMaker struct {
Expand All @@ -16,7 +17,8 @@ type DirDatabaseTarBallComposerMaker struct {
tarFileSets internal.TarFileSets
}

func NewDirDatabaseTarBallComposerMaker(files internal.BundleFiles, filePackerOptions TarBallFilePackerOptions, tarFileSets internal.TarFileSets) *DirDatabaseTarBallComposerMaker {
func NewDirDatabaseTarBallComposerMaker(files internal.BundleFiles, filePackerOptions TarBallFilePackerOptions,
tarFileSets internal.TarFileSets) *DirDatabaseTarBallComposerMaker {
return &DirDatabaseTarBallComposerMaker{
files: files,
filePackerOptions: filePackerOptions,
Expand Down Expand Up @@ -53,7 +55,6 @@ func newDirDatabaseTarBallComposer(
sets internal.TarFileSets,
crypter crypto.Crypter,
) *DirDatabaseTarBallComposer {

return &DirDatabaseTarBallComposer{
files: files,
tarBallQueue: tarBallQueue,
Expand Down Expand Up @@ -118,7 +119,6 @@ func (d DirDatabaseTarBallComposer) addListToTar(files []*internal.ComposeFileIn
tarBall.SetUp(d.crypter)

for _, file := range files {

d.tarFileSets.AddFile(tarBall.Name(), file.Header.Name)
err := d.tarFilePacker.PackFileIntoTar(file, tarBall)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/delete_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
DeleteTargetExamples = ` target base_0000000100000000000000C4 delete base backup by name
target --target-user-data "{ \"x\": [3], \"y\": 4 }" delete backup specified by user data
target base_0000000100000000000000C9_D_0000000100000000000000C4 delete delta backup and all dependant delta backups
target FIND_FULL base_0000000100000000000000C9_D_0000000100000000000000C4 delete delta backup and all delta backups with the same base backup` //nolint:lll
target FIND_FULL base_0000000100000000000000C9_D_0000000100000000000000C4 delete delta backup and all delta backups with the same base backup` //nolint:lll

DeleteEverythingUsageExample = "everything [FORCE]"
DeleteRetainUsageExample = "retain [FULL|FIND_FULL] backup_count"
Expand Down
6 changes: 4 additions & 2 deletions internal/splitmerge/splitmerge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ func (b *BufferCloser) Close() error {
return nil
}

// ┌─> copy data per 1 byte ─>┐
// ┌─> copy data per 1 byte ─>┐
//
// data ─> split ├─> copy data per ... bytes ─>├─> merge
// └─> copy data per 42 bytes ─>┘
//
// └─> copy data per 42 bytes ─>┘
func TestSplitMerge(t *testing.T) {
const blockSize = 128
const dataSize = 115249 // some prime number
Expand Down
110 changes: 55 additions & 55 deletions pkg/storages/storage/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package storage

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParsePrefixAsURL_URLInvalid(t *testing.T) {
_, _, err := ParsePrefixAsURL("\r\n")
assert.Error(t, err)
}

func TestParsePrefixAsURL_NoHostOrSchemaFound(t *testing.T) {
urls := []string{
"host.com/path",
"/relative-path",
"",
}

for _, url := range urls {
_, _, err := ParsePrefixAsURL(url)
assert.Error(t, err)
}
}

func TestParsePrefixAsURL(t *testing.T) {
testcases := []struct{ url, bucket, server string }{
{url: "http://host.com", bucket: "host.com", server: ""},
{url: "http://host.com/", bucket: "host.com", server: "/"},
{url: "http://admin:pass@www.host.com:8080/path?v=query#anchor", bucket: "www.host.com:8080", server: "/path"},
}

for _, tc := range testcases {
bucket, server, err := ParsePrefixAsURL(tc.url)
assert.Nil(t, err)
assert.Equal(t, tc.bucket, bucket)
assert.Equal(t, tc.server, server)
}
}

func TestGetPathFromPrefix(t *testing.T) {
testcases := []struct{ url, bucket, server string }{
{url: "http://host.com", bucket: "host.com", server: ""},
{url: "http://host.com/", bucket: "host.com", server: ""},
{url: "http://admin:pass@www.host.com:8080/path?v=query#anchor", bucket: "www.host.com:8080", server: "path"},
}

for _, tc := range testcases {
bucket, server, err := GetPathFromPrefix(tc.url)
assert.Nil(t, err)
assert.Equal(t, tc.bucket, bucket)
assert.Equal(t, tc.server, server)
}
}
package storage

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParsePrefixAsURL_URLInvalid(t *testing.T) {
_, _, err := ParsePrefixAsURL("\r\n")
assert.Error(t, err)
}

func TestParsePrefixAsURL_NoHostOrSchemaFound(t *testing.T) {
urls := []string{
"host.com/path",
"/relative-path",
"",
}

for _, url := range urls {
_, _, err := ParsePrefixAsURL(url)
assert.Error(t, err)
}
}

func TestParsePrefixAsURL(t *testing.T) {
testcases := []struct{ url, bucket, server string }{
{url: "http://host.com", bucket: "host.com", server: ""},
{url: "http://host.com/", bucket: "host.com", server: "/"},
{url: "http://admin:pass@www.host.com:8080/path?v=query#anchor", bucket: "www.host.com:8080", server: "/path"},
}

for _, tc := range testcases {
bucket, server, err := ParsePrefixAsURL(tc.url)
assert.Nil(t, err)
assert.Equal(t, tc.bucket, bucket)
assert.Equal(t, tc.server, server)
}
}

func TestGetPathFromPrefix(t *testing.T) {
testcases := []struct{ url, bucket, server string }{
{url: "http://host.com", bucket: "host.com", server: ""},
{url: "http://host.com/", bucket: "host.com", server: ""},
{url: "http://admin:pass@www.host.com:8080/path?v=query#anchor", bucket: "www.host.com:8080", server: "path"},
}

for _, tc := range testcases {
bucket, server, err := GetPathFromPrefix(tc.url)
assert.Nil(t, err)
assert.Equal(t, tc.bucket, bucket)
assert.Equal(t, tc.server, server)
}
}
8 changes: 4 additions & 4 deletions testtools/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,16 @@ var ErrorMockClose = errors.New("mock close: close error")
var ErrorMockRead = errors.New("mock reader: read error")
var ErrorMockWrite = errors.New("mock writer: write error")

//ErrorWriter struct implements io.Writer interface.
//Its Write method returns zero and non-nil error on every call
// ErrorWriter struct implements io.Writer interface.
// Its Write method returns zero and non-nil error on every call
type ErrorWriter struct{}

func (w ErrorWriter) Write(b []byte) (int, error) {
return 0, ErrorMockWrite
}

//ErrorReader struct implements io.Reader interface.
//Its Read method returns zero and non-nil error on every call
// ErrorReader struct implements io.Reader interface.
// Its Read method returns zero and non-nil error on every call
type ErrorReader struct{}

func (r ErrorReader) Read(b []byte) (int, error) {
Expand Down

0 comments on commit deeefb2

Please sign in to comment.