1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
//go:build darwin
// +build darwin
package tools
import (
"os"
"path"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCheckCloneFileSupported(t *testing.T) {
as := assert.New(t)
// Do
ok, err := CheckCloneFileSupported(os.TempDir())
// Verify
t.Logf("ok = %v, err = %v", ok, err) // Just logging for 1st element
if !checkCloneFileSupported() {
as.EqualError(err, "unsupported OS version. >= 10.12.x Sierra required")
}
}
func TestCloneFile(t *testing.T) {
as := assert.New(t)
// Do
ok, err := CloneFile(nil, nil)
// Verify always no error and not ok
as.NoError(err)
as.False(ok)
}
func TestCloneFileByPath(t *testing.T) {
if !cloneFileSupported {
t.Skip("clone not supported on this platform")
}
src := path.Join(os.TempDir(), "src")
t.Logf("src = %s", src)
dst := path.Join(os.TempDir(), "dst")
t.Logf("dst = %s", dst)
as := assert.New(t)
// Precondition
err := os.WriteFile(src, []byte("TEST"), 0666)
as.NoError(err)
// Do
ok, err := CloneFileByPath(dst, src)
if err != nil {
if cloneFileError, ok := err.(*CloneFileError); ok && cloneFileError.Unsupported {
t.Log(err)
t.Skip("tmp file is not support clonefile in this os installation.")
}
t.Error(err)
}
// Verify
as.NoError(err)
as.True(ok)
dstContents, err := os.ReadFile(dst)
as.NoError(err)
as.Equal("TEST", string(dstContents))
}
|