This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
94 lines (73 loc) · 1.79 KB
/
parser_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
package safeincloud
import (
"io/ioutil"
"reflect"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseFileOpenError(t *testing.T) {
t.Parallel()
// arrange
// act
db, err := ParseFile("blah")
// assert
assert.Nil(t, db)
assert.Error(t, err)
assert.Contains(t, err.Error(), "os.Open()")
}
func TestParseReaderNilError(t *testing.T) {
t.Parallel()
// arrange
// act
db, err := ParseReader(nil)
// assert
assert.Nil(t, db)
assert.Error(t, err)
assert.Contains(t, err.Error(), "io.Reader")
}
func TestParseReaderDecoderError(t *testing.T) {
t.Parallel()
// arrange
r := strings.NewReader("")
// act
db, err := ParseReader(r)
// assert
assert.Nil(t, db)
assert.Error(t, err)
assert.Contains(t, err.Error(), "decoder.Decode()")
}
func TestValidateBase64Attachments(t *testing.T) {
t.Parallel()
// arrange
attachments := map[string]string{
"file": "the-evolution-of-house-cats.pdf.gpg",
"image": "cutecat.jpg",
}
// act
db, err := ParseFile("testdata/safeincloud.xml")
// assert
assert.NoError(t, err)
assert.NotNil(t, db)
found := false
for _, c := range db.Cards {
if c.Title == "Attachment Example" {
found = true
assert.EqualValues(t, 1, len(c.Files))
assert.EqualValues(t, 1, len(c.Images))
// validate the file attachment
f := c.Files[0]
assert.EqualValues(t, attachments["file"], f.Name)
file, err := ioutil.ReadFile("testdata/" + attachments["file"])
if err != nil {
panic(err)
}
assert.True(t, reflect.DeepEqual(f.Value, file), "file bytes did not match")
// images cannot be validated as SafeInCloud compresses
// ALL IMAGES to jpeg 80% regardless of type or size which
// completely changes the image itself. :(
//
}
}
assert.True(t, found, "card title not found 'Attachment Example'")
}