-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
262 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Go Test | ||
on: [push] | ||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.23 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.23 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v1 | ||
|
||
- name: Test | ||
run: | | ||
make | ||
go test -v ./... | ||
- name: StoreBinaries | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Binaries | ||
path: vmdk* |
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
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,78 @@ | ||
package parser | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/sebdah/goldie" | ||
) | ||
|
||
type MockExtent struct { | ||
*SparseExtent | ||
|
||
buf []byte | ||
} | ||
|
||
func (self *MockExtent) ReadAt(buf []byte, offset int64) (int, error) { | ||
for i := 0; i < len(buf); i++ { | ||
buf[i] = self.buf[i+int(offset)] | ||
} | ||
|
||
return len(buf), nil | ||
} | ||
|
||
func makeData(offset, length int) string { | ||
res := "" | ||
for len(res) < length { | ||
res += fmt.Sprintf(" % 4d", offset+len(res)) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func NewMockExtent(offset, total_size int64) Extent { | ||
return &MockExtent{ | ||
SparseExtent: &SparseExtent{ | ||
offset: offset, | ||
total_size: total_size, | ||
}, | ||
buf: []byte(makeData(int(offset), int(total_size))), | ||
} | ||
} | ||
|
||
func TestFindExtent(t *testing.T) { | ||
res := &VMDKContext{ | ||
total_size: 350, | ||
extents: []Extent{ | ||
NewMockExtent(0, 100), | ||
NewMockExtent(100, 100), | ||
// Gap | ||
NewMockExtent(300, 50), | ||
}, | ||
} | ||
|
||
res.normalizeExtents() | ||
var golden []string | ||
|
||
for _, offset := range []int64{0, 5, 95, 210, 290, 340} { | ||
buf := make([]byte, 20) | ||
|
||
extent, err := res.getExtentForOffset(offset) | ||
if err != nil { | ||
golden = append(golden, | ||
fmt.Sprintf("err for %v %v\n", offset, err)) | ||
} else { | ||
golden = append(golden, | ||
fmt.Sprintf("extent for %v %v, err %v\n", | ||
offset, extent.Stats(), err)) | ||
} | ||
|
||
n, err := res.ReadAt(buf, offset) | ||
golden = append(golden, | ||
fmt.Sprintf("Reading %v (%v) : %v (%v)\n", offset, n, | ||
string(buf[:n]), err)) | ||
} | ||
|
||
goldie.Assert(t, "TestFindExtent", []byte(strings.Join(golden, "\n"))) | ||
} |
Binary file not shown.
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,34 @@ | ||
package parser | ||
|
||
import "io" | ||
|
||
type NullExtent struct { | ||
SparseExtent | ||
} | ||
|
||
func (self *NullExtent) ReadAt(buf []byte, offset int64) (int, error) { | ||
if offset < 0 || offset > self.total_size { | ||
return 0, io.EOF | ||
} | ||
|
||
to_read := int64(len(buf)) | ||
available_length := self.total_size - offset | ||
if to_read > available_length { | ||
to_read = available_length | ||
} | ||
|
||
for i := int64(0); i < to_read; i++ { | ||
buf[i] = 0 | ||
} | ||
|
||
return int(to_read), nil | ||
} | ||
|
||
func (self *NullExtent) Stats() ExtentStat { | ||
return ExtentStat{ | ||
Type: "PAD", | ||
VirtualOffset: self.offset, | ||
Size: self.total_size, | ||
Filename: self.filename, | ||
} | ||
} |
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,13 @@ | ||
package parser | ||
|
||
import "io" | ||
|
||
type Extent interface { | ||
io.ReaderAt | ||
|
||
VirtualOffset() int64 | ||
TotalSize() int64 | ||
Stats() ExtentStat | ||
Close() | ||
Debug() | ||
} |
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.