This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck-size_test.go
107 lines (91 loc) · 2.05 KB
/
check-size_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
106
107
//
// Test for our size-detecting plugin.
//
package main
import (
"strings"
"testing"
)
func TestSizeHam(t *testing.T) {
//
// Test a simple comment.
//
result, detail := validateEmail(Submission{Comment: "I like to eat cakes",
Options: "min-size=1,max-size=100"})
if result != Undecided {
t.Errorf("Unexpected response: '%v'", result)
}
if len(detail) != 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
}
//
// Test broken size-options
//
func TestSizeBrokenOptions(t *testing.T) {
//
// Test several options
//
inputs := []string{"min-size=b",
"min-size=-1",
"max-size=pi",
"max-size=-5"}
for _, input := range inputs {
result, detail := validateSize(Submission{Comment: "Foo, bar", Options: input})
if result != Error {
t.Errorf("Unexpected response '%v'", result)
}
if len(detail) == 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
if !strings.Contains(detail, "Failed to parse") {
t.Errorf("Unexpected response: '%v'", detail)
}
}
}
//
// Test too small.
//
func TestSizeTooSmall(t *testing.T) {
//
// Test several options
//
inputs := []string{"moi",
"hello"}
for _, input := range inputs {
result, detail := validateSize(Submission{Comment: input,
Options: "min-size=100"})
if result != Spam {
t.Errorf("Unexpected response: '%v'", result)
}
if len(detail) == 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
if !strings.Contains(detail, "minimum size") {
t.Errorf("Unexpected response: '%v'", detail)
}
}
}
//
// Test too large
//
func TestSizeTooLarge(t *testing.T) {
//
// Test several comments
//
inputs := []string{"This is a huge comment, honest",
"I like big books and I cannot lie"}
for _, input := range inputs {
result, detail := validateSize(Submission{Comment: input,
Options: "max-size=10"})
if result != Spam {
t.Errorf("Unexpected response: '%v'", result)
}
if len(detail) == 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
if !strings.Contains(detail, "maximum size") {
t.Errorf("Unexpected response: '%v'", detail)
}
}
}