-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcap_test.go
44 lines (38 loc) · 911 Bytes
/
cap_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
package cap
import (
"archive/zip"
"testing"
)
func TestParse(t *testing.T) {
tests := []struct {
name string
capFilename string
expectError bool
}{
{
name: "parsing CAP without header component is expected to fail",
capFilename: "./test-files/no-header.cap",
expectError: true,
},
{
name: "parsing CAP with invalid 0 component is expected to fail",
capFilename: "./test-files/invalid-0-component.cap",
expectError: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
zf, err := zip.OpenReader(tc.capFilename)
if err != nil {
t.Fatalf("unable to open cap file %s: %s", tc.capFilename, err)
}
if zf != nil {
defer zf.Close()
}
_, err = Parse(&zf.Reader)
if tc.expectError != (err != nil) {
t.Fatalf("error expected: %t, actual: %t, err: %s", tc.expectError, err != nil, err)
}
})
}
}