-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compute the layer size from tar-split for zstd:chunked layers
Signed-off-by: Miloslav Trmač <[email protected]>
- Loading branch information
Showing
3 changed files
with
112 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package chunked | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/vbatts/tar-split/archive/tar" | ||
"github.com/vbatts/tar-split/tar/asm" | ||
"github.com/vbatts/tar-split/tar/storage" | ||
) | ||
|
||
func TestTarSizeFromTarSplit(t *testing.T) { | ||
var tarball bytes.Buffer | ||
tarWriter := tar.NewWriter(&tarball) | ||
for _, e := range someFiles { | ||
tf, err := typeToTarType(e.Type) | ||
require.NoError(t, err) | ||
err = tarWriter.WriteHeader(&tar.Header{ | ||
Typeflag: tf, | ||
Name: e.Name, | ||
Size: e.Size, | ||
Mode: e.Mode, | ||
}) | ||
require.NoError(t, err) | ||
data := make([]byte, e.Size) | ||
_, err = tarWriter.Write(data) | ||
require.NoError(t, err) | ||
} | ||
err := tarWriter.Close() | ||
require.NoError(t, err) | ||
expectedTarSize := tarball.Len() | ||
|
||
var tarSplit bytes.Buffer | ||
tsReader, err := asm.NewInputTarStream(&tarball, storage.NewJSONPacker(&tarSplit), storage.NewDiscardFilePutter()) | ||
require.NoError(t, err) | ||
_, err = io.Copy(io.Discard, tsReader) | ||
require.NoError(t, err) | ||
|
||
res, err := tarSizeFromTarSplit(tarSplit.Bytes()) | ||
require.NoError(t, err) | ||
assert.Equal(t, expectedTarSize, res) | ||
} |
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