-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
clone_test.go
113 lines (106 loc) · 2.35 KB
/
clone_test.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2017 The go-darwin Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin
package apfs
import (
"os"
"path/filepath"
"testing"
)
func TestCloneFile(t *testing.T) {
type args struct {
src string
dst string
flag CLONEFILE_FLAG
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "simple",
args: args{
src: testFile,
dst: filepath.Join(mountPoint, "clonefile.txt"),
flag: CLONEFILE_FLAG(0),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := CloneFile(tt.args.src, tt.args.dst, tt.args.flag)
_, statErr := os.Stat(tt.args.dst)
if (err != nil && statErr != nil) != tt.wantErr {
t.Errorf("CloneFile(%v, %v, %v) error = %v, wantErr %v", tt.args.src, tt.args.dst, tt.args.flag, err, tt.wantErr)
}
})
}
}
func TestCloneFileAt(t *testing.T) {
type args struct {
src string
dst string
flag CLONEFILE_FLAG
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "simple",
args: args{
src: testFile,
dst: filepath.Join(mountPoint, "clonefileat.txt"),
flag: CLONEFILE_FLAG(0),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := CloneFileAt(tt.args.src, tt.args.dst, tt.args.flag); (err != nil) != tt.wantErr {
t.Errorf("CloneFileAt(%v, %v, %v) error = %v, wantErr %v", tt.args.src, tt.args.dst, tt.args.flag, err, tt.wantErr)
}
})
}
}
func TestFcloneFileAt(t *testing.T) {
type args struct {
srcFd uintptr
dst string
flag CLONEFILE_FLAG
}
tests := []struct {
name string
file string
args args
wantErr bool
}{
{
name: "simple",
args: args{
dst: filepath.Join(mountPoint, "fclonefileat.txt"),
flag: CLONEFILE_FLAG(0),
},
file: testFile,
wantErr: false,
},
}
for _, tt := range tests {
fi, err := os.Open(tt.file)
if err != nil {
t.Fatal(err)
}
defer fi.Close()
tt.args.srcFd = fi.Fd()
t.Run(tt.name, func(t *testing.T) {
if err := FcloneFileAt(tt.args.srcFd, tt.args.dst, tt.args.flag); (err != nil) != tt.wantErr {
t.Errorf("FcloneFileAt(%v, %v, %v) error = %v, wantErr %v", tt.args.srcFd, tt.args.dst, tt.args.flag, err, tt.wantErr)
}
})
}
}