-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors_test.go
105 lines (84 loc) · 2.39 KB
/
errors_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
package magic
import (
"reflect"
"testing"
)
func TestError(t *testing.T) {
mgc, err := New()
if err != nil {
t.Fatalf("unable to create new Magic type: %s", err.Error())
}
defer mgc.Close()
err = mgc.error()
func(v interface{}) {
if _, ok := v.(*Error); !ok {
t.Fatalf("not a Error type: %s", reflect.TypeOf(v).String())
}
}(err)
}
// func TestError_Error(t *testing.T) {
// var v string
// mgc, err := New()
// if err != nil {
// t.Fatalf("unable to create new Magic type: %s", err.Error())
// }
// defer mgc.Close()
// v = "magic: an unknown error has occurred"
// if n := Version(); n < 518 && n >= 514 {
// // A few releases of libmagic were having issues.
// v = "magic: no magic files loaded"
// }
// err = mgc.error()
// if ok := compareStrings(err.Error(), v); !ok {
// t.Errorf("value given %q, want %q", err.Error(), v)
// }
// v = "the quick brown fox jumps over the lazy dog"
// err = &Error{0, v}
// if ok := compareStrings(err.Error(), fmt.Sprintf("magic: %s", v)); !ok {
// t.Errorf("value given %q, want %q", err.Error(), v)
// }
// }
// func TestError_Errno(t *testing.T) {
// var v int
// mgc, err := New()
// if err != nil {
// t.Fatalf("unable to create new Magic type: %s", err.Error())
// }
// defer mgc.Close()
// v = -1
// if n := Version(); n < 518 && n >= 514 {
// // A few releases of libmagic were having issues.
// v = 0
// }
// err = mgc.error()
// if err.(*Error).Errno != v {
// t.Errorf("value given %d, want %d", err.(*Error).Errno, v)
// }
// v = 42
// err = &Error{v, ""}
// if err.(*Error).Errno != v {
// t.Errorf("value given %d, want %d", err.(*Error).Errno, v)
// }
// }
// func TestError_Message(t *testing.T) {
// var v string
// mgc, err := New()
// if err != nil {
// t.Fatalf("unable to create new Magic type: %s", err.Error())
// }
// defer mgc.Close()
// v = "an unknown error has occurred"
// if n := Version(); n < 518 && n >= 514 {
// // A few releases of libmagic were having issues.
// v = "no magic files loaded"
// }
// err = mgc.error()
// if ok := compareStrings(err.(*Error).Message, v); !ok {
// t.Errorf("value given %q, want %q", err.(*Error).Message, v)
// }
// v = "the quick brown fox jumps over the lazy dog"
// err = &Error{0, v}
// if ok := compareStrings(err.(*Error).Message, v); !ok {
// t.Errorf("value given %q, want %q", err.(*Error).Message, v)
// }
// }