Use temp file for export/import test
Using a bytes buffer for this test increases the memory usage on Windows to over 3 GB. Using a temporary file as a destination for the image keeps memory usage at a reasonable level. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
@@ -18,8 +18,9 @@ package client
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
. "github.com/containerd/containerd"
|
||||
@@ -45,12 +46,23 @@ func TestExport(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wb := bytes.NewBuffer(nil)
|
||||
err = client.Export(ctx, wb, archive.WithPlatform(platforms.Default()), archive.WithImage(client.ImageService(), testImage))
|
||||
dstFile, err := ioutil.TempFile("", "export-import-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertOCITar(t, bytes.NewReader(wb.Bytes()))
|
||||
defer func() {
|
||||
dstFile.Close()
|
||||
os.Remove(dstFile.Name())
|
||||
}()
|
||||
|
||||
err = client.Export(ctx, dstFile, archive.WithPlatform(platforms.Default()), archive.WithImage(client.ImageService(), testImage))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Seet to begining of file before passing it to assertOCITar()
|
||||
dstFile.Seek(0, 0)
|
||||
assertOCITar(t, dstFile)
|
||||
}
|
||||
|
||||
func assertOCITar(t *testing.T, r io.Reader) {
|
||||
|
Reference in New Issue
Block a user