-
Notifications
You must be signed in to change notification settings - Fork 3
/
revisit_msg_test.go
59 lines (49 loc) · 1.33 KB
/
revisit_msg_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
package gorevisit
import (
"testing"
)
func TestNewRevisitMsgFromFilesWithJPEG(t *testing.T) {
msg, err := NewRevisitMsgFromFiles("./fixtures/bob.jpg")
if err != nil {
t.Error(err)
}
if msg.ImageType() != "image/jpeg" {
t.Errorf("image type should be 'image/jpeg' is %s", msg.ImageType())
}
}
func TestNewRevisitMsgFromFilesWithGIF(t *testing.T) {
msg, err := NewRevisitMsgFromFiles("./fixtures/bob.gif")
if err != nil {
t.Error(err)
}
if msg.ImageType() != "image/gif" {
t.Errorf("image type should be 'image/gif' is %s", msg.ImageType())
}
}
func TestNewRevisitMsgFromFilesWithPNG(t *testing.T) {
msg, err := NewRevisitMsgFromFiles("./fixtures/connie.png")
if err != nil {
t.Error(err)
}
if msg.ImageType() != "image/png" {
t.Errorf("image type should be 'image/png' is %s", msg.ImageType())
}
}
func TestIsValidSize(t *testing.T) {
bigImageBytes := make([]byte, 2000000)
bigImage := &ImageData{Data: string(bigImageBytes)}
msg := &RevisitMsg{
Content: *bigImage,
}
if msg.IsValidSize() == true {
t.Error("image should be too large but IsValidSize returned true")
}
smallImageBytes := make([]byte, 200)
smallImage := &ImageData{Data: string(smallImageBytes)}
msg = &RevisitMsg{
Content: *smallImage,
}
if msg.IsValidSize() == false {
t.Error("image should be fine but IsValidSize returned false")
}
}