-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
65 lines (58 loc) · 1.95 KB
/
Copy patherrors_test.go
File metadata and controls
65 lines (58 loc) · 1.95 KB
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
package pcsc
import (
"errors"
"testing"
)
func TestPCSCErrorMatchesStableErrors(t *testing.T) {
tests := []struct {
code uint32
want error
}{
{code: 0x80100002, want: ErrCanceled},
{code: 0x80100008, want: ErrInsufficientBuffer},
{code: 0x80100009, want: ErrUnknownReader},
{code: 0x8010000a, want: ErrTimeout},
{code: 0x8010000b, want: ErrSharingViolation},
{code: 0x8010000c, want: ErrNoCard},
{code: 0x8010000e, want: ErrCannotDispose},
{code: 0x8010000f, want: ErrProtocolMismatch},
{code: 0x80100010, want: ErrNotReady},
{code: 0x80100016, want: ErrNotTransacted},
{code: 0x80100017, want: ErrReaderUnavailable},
{code: 0x8010001d, want: ErrNoService},
{code: 0x8010001e, want: ErrServiceStopped},
{code: 0x8010002e, want: ErrNoReaders},
{code: 0x80100068, want: ErrCardReset},
{code: 0x80100069, want: ErrCardRemoved},
}
for _, test := range tests {
err := pcscError("test", test.code)
if !errors.Is(err, test.want) {
t.Errorf("pcscError(0x%08x) = %v, want errors.Is(_, %v)", test.code, err, test.want)
}
}
}
func TestEveryDocumentedErrorCodeHasStableError(t *testing.T) {
for _, table := range []map[uint32]errorInfo{errorsByCode, platformErrorsByCode} {
for code, info := range table {
err := pcscError("test", code)
if !errors.Is(err, info.err) {
t.Errorf("pcscError(0x%08x) = %v, want errors.Is(_, %v)", code, err, info.err)
}
}
}
}
func TestUnsupportedFeatureUsesPlatformCode(t *testing.T) {
err := pcscError("test", unsupportedFeatureCode)
if !errors.Is(err, ErrUnsupportedFeature) {
t.Fatalf("pcscError(0x%08x) = %v, want ErrUnsupportedFeature", unsupportedFeatureCode, err)
}
if unsupportedFeatureCode == 0x8010001f && !errors.Is(err, ErrUnexpected) {
t.Fatalf("pcsc-lite collision no longer matches ErrUnexpected: %v", err)
}
}
func TestPCSCErrorDoesNotMatchNil(t *testing.T) {
if errors.Is(pcscError("test", 0x80100002), nil) {
t.Fatal("mapped PC/SC error unexpectedly matches nil")
}
}