generated from OtusGolang/home_work
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_test.go
70 lines (55 loc) · 1.16 KB
/
copy_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
package main
import (
"fmt"
"io"
"log"
"os"
"testing"
"github.com/stretchr/testify/require"
)
const toPath = "./testdata/out.txt"
func TestCopy(t *testing.T) {
t.Run("bad file", func(t *testing.T) {
fromPath := "./testdata/input1.txt"
offset = 6000
limit = 0
err := Copy(fromPath, toPath, offset, limit)
if err != nil {
fmt.Println(err)
}
require.EqualError(t, err, "unsupported file")
})
}
func TestCopy2(t *testing.T) {
t.Run("big offset", func(t *testing.T) {
fromPath := "./testdata/input.txt"
offset = 8000
limit = 0
err := Copy(fromPath, toPath, offset, limit)
if err != nil {
fmt.Println(err)
}
require.EqualError(t, err, "offset exceeds file size")
})
}
func TestCopy3(t *testing.T) {
t.Run("len new file", func(t *testing.T) {
fromPath := "./testdata/input.txt"
offset = 3000
limit = 1000
err := Copy(fromPath, toPath, offset, limit)
if err != nil {
fmt.Println(err)
}
file, err := os.Open(toPath)
if err != nil {
log.Fatal("Нет файла")
}
buf, er := io.ReadAll(file)
if er != nil {
log.Fatal("не прочитал")
}
require.Len(t, buf, 1000)
require.NoError(t, err)
})
}