mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

Added the module github.com/crc-org/crc/ as a dependency. Updated `decompress.go` and `copy_test.go` in compression so that `CopySparse` from crc-org/crc/v2/pkg/os is used instead of the local version in `copy.go`. Deleted `copy.go` that is not used anymore. Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
55 lines
971 B
Go
55 lines
971 B
Go
package compression
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
crcOs "github.com/crc-org/crc/v2/pkg/os"
|
|
)
|
|
|
|
func TestCopyFile(t *testing.T) {
|
|
testStr := "test-machine"
|
|
|
|
srcFile, err := os.CreateTemp("", "machine-test-")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
srcFi, err := srcFile.Stat()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, _ = srcFile.Write([]byte(testStr)) //nolint:mirror
|
|
srcFile.Close()
|
|
|
|
srcFilePath := filepath.Join(os.TempDir(), srcFi.Name())
|
|
|
|
destFile, err := os.CreateTemp("", "machine-copy-test-")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
destFi, err := destFile.Stat()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
destFile.Close()
|
|
|
|
destFilePath := filepath.Join(os.TempDir(), destFi.Name())
|
|
|
|
if err := crcOs.CopyFile(srcFilePath, destFilePath); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
data, err := os.ReadFile(destFilePath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if string(data) != testStr {
|
|
t.Fatalf("expected data \"%s\"; received \"%s\"", testStr, string(data))
|
|
}
|
|
}
|