generated from OtusGolang/home_work
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_test.go
34 lines (27 loc) · 937 Bytes
/
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
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
const (
destinationFile = "/tmp/test-1.txt"
sourceFile = "./testdata/input.txt"
)
func TestCopy(t *testing.T) {
t.Run("returns ErrOffsetExceedsFileSize error when offset is bigger than file size", func(t *testing.T) {
err := Copy("./testdata/input.txt", destinationFile, 7000, 0)
require.ErrorIs(t, err, ErrOffsetExceedsFileSize)
})
t.Run("returns ErrUnsupportedFile error when source file is not regular file", func(t *testing.T) {
err := Copy("/dev/random", destinationFile, 0, 0)
require.ErrorIs(t, err, ErrUnsupportedFile)
})
t.Run("returns ErrUnsupportedFile error when source file is directory", func(t *testing.T) {
err := Copy("/tmp", destinationFile, 0, 0)
require.ErrorIs(t, err, ErrUnsupportedFile)
})
t.Run("test", func(t *testing.T) {
err := Copy(sourceFile, destinationFile, 0, 10)
require.NoError(t, err)
})
}