forked from mholt/archiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
52 lines (45 loc) · 1.31 KB
/
error_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
package archiver_test
import (
"errors"
"fmt"
"os"
"testing"
)
func TestIllegalPathErrorString(t *testing.T) {
tests := []struct {
instance *archiver.IllegalPathError
expected string
}{
{instance: &archiver.IllegalPathError{Filename: "foo.txt"}, expected: "illegal file path: foo.txt"},
{instance: &archiver.IllegalPathError{AbsolutePath: "/tmp/bar.txt", Filename: "bar.txt"}, expected: "illegal file path: bar.txt"},
}
for i, test := range tests {
test := test
t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) {
if test.expected != test.instance.Error() {
t.Fatalf("Excepected '%s', but got '%s'", test.expected, test.instance.Error())
}
})
}
}
func TestIsIllegalPathError(t *testing.T) {
tests := []struct {
instance error
expected bool
}{
{instance: nil, expected: false},
{instance: os.ErrNotExist, expected: false},
{instance: fmt.Errorf("some error"), expected: false},
{instance: errors.New("another error"), expected: false},
{instance: &archiver.IllegalPathError{Filename: "foo.txt"}, expected: true},
}
for i, test := range tests {
test := test
t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) {
actual := archiver.IsIllegalPathError(test.instance)
if actual != test.expected {
t.Fatalf("Excepected '%v', but got '%v'", test.expected, actual)
}
})
}
}