forked from wal-g/wal-g
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests, docs, minor fixes (wal-g#1337)
- Loading branch information
1 parent
3e1f315
commit 7c2fd58
Showing
9 changed files
with
512 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package greenplum_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/wal-g/wal-g/internal/databases/greenplum" | ||
"github.com/wal-g/wal-g/internal/walparser/parsingutil" | ||
"io" | ||
"os" | ||
"testing" | ||
) | ||
|
||
const aoSegmentFileName = "../../../test/testdata/gp_ao_file.bin" | ||
const aoSegmentFileSizeBytes = 192 | ||
|
||
func TestReadIncrement(t *testing.T) { | ||
gpReadIncrement(10, 100, t) | ||
} | ||
|
||
func TestReadIncrementFull(t *testing.T) { | ||
gpReadIncrement(0, aoSegmentFileSizeBytes, t) | ||
} | ||
|
||
func TestFailOnIncorrectOffset(t *testing.T) { | ||
file, err := os.Open(aoSegmentFileName) | ||
if err != nil { | ||
fmt.Print(err.Error()) | ||
} | ||
|
||
_, err = greenplum.NewIncrementalPageReader(file, aoSegmentFileSizeBytes, aoSegmentFileSizeBytes) | ||
assert.Error(t, err) | ||
|
||
_, err = greenplum.NewIncrementalPageReader(file, 0, aoSegmentFileSizeBytes) | ||
assert.Error(t, err) | ||
} | ||
|
||
func gpReadIncrement(offset, eof int64, t *testing.T) { | ||
file, err := os.Open(aoSegmentFileName) | ||
if err != nil { | ||
fmt.Print(err.Error()) | ||
} | ||
|
||
reader, err := greenplum.NewIncrementalPageReader(file, eof, offset) | ||
assert.NoError(t, err) | ||
|
||
increment, err := io.ReadAll(reader) | ||
assert.NoError(t, err) | ||
|
||
incrementBuf := bytes.NewBuffer(increment) | ||
err = greenplum.ReadIncrementFileHeader(incrementBuf) | ||
assert.NoError(t, err) | ||
|
||
var parsedEof uint64 | ||
var parsedOffset uint64 | ||
err = parsingutil.ParseMultipleFieldsFromReader([]parsingutil.FieldToParse{ | ||
{Field: &parsedEof, Name: "eof"}, | ||
{Field: &parsedOffset, Name: "offset"}, | ||
}, incrementBuf) | ||
|
||
assert.Equal(t, parsedOffset, uint64(offset)) | ||
assert.Equal(t, parsedEof, uint64(eof)) | ||
|
||
_, _ = file.Seek(offset, io.SeekStart) | ||
|
||
fileFragment := new(bytes.Buffer) | ||
_, _ = io.CopyN(fileFragment, file, eof-offset) | ||
|
||
assert.True(t, bytes.Equal(fileFragment.Bytes(), incrementBuf.Bytes())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.