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
/
check-mandatory_test.go
101 lines (83 loc) · 2.33 KB
/
check-mandatory_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
//
// Test for our mandatory-fields plugin.
//
package main
import (
"strings"
"testing"
)
//
// Test that all is OK when the minimum required fields are present.
//
func TestMandatoryOK(t *testing.T) {
result, _ := validateMandatory(Submission{Site: "example",
IP: "1.2.3.4", Comment: "This is a test"})
if result != Undecided {
t.Errorf("Unexpected response: '%v'", result)
}
}
//
// Test that all is OK when the minimum required fields are present, as well
// as a single extra mandatory field
//
func TestMandatoryOKExtra(t *testing.T) {
result, _ := validateMandatory(Submission{Site: "example",
IP: "1.2.3.4", Comment: "This is a test",
Options: "mandatory=agent", Agent: "foo"})
if result != Undecided {
t.Errorf("Unexpected response: '%v'", result)
}
}
//
// Test that we receive an alert if we're missing a `site` parameter.
//
func TestMandatoryMissingSite(t *testing.T) {
result, detail := validateMandatory(Submission{Site: "",
IP: "1.2.3.4", Comment: "This is a test"})
if result != Spam {
t.Errorf("Unexpected response: '%v'", result)
}
if !strings.Contains(detail, "is missing") {
t.Errorf("Unexpected response: '%v'", detail)
}
}
//
// Test that we receive an alert if we're missing a `ip` parameter.
//
func TestMandatoryMissingIP(t *testing.T) {
result, detail := validateMandatory(Submission{Site: "steve.fi",
IP: "", Comment: "This is a test"})
if result != Spam {
t.Errorf("Unexpected response: '%v'", result)
}
if !strings.Contains(detail, "is missing") {
t.Errorf("Unexpected response: '%v'", detail)
}
}
//
// Test that we receive an alert if we're missing a `comment` parameter.
//
func TestMandatoryMissingComment(t *testing.T) {
result, detail := validateMandatory(Submission{Site: "fsdf",
IP: "1.2.3.4"})
if result != Spam {
t.Errorf("Unexpected response: '%v'", result)
}
if !strings.Contains(detail, "is missing") {
t.Errorf("Unexpected response: '%v'", detail)
}
}
//
// Test that we receive an alert if we're missing an extra `agent` parameter.
//
func TestMandatoryMissingAgent(t *testing.T) {
result, detail := validateMandatory(Submission{Site: "fsdf",
IP: "1.2.3.4",
Options: "mandatory=agent"})
if result != Spam {
t.Errorf("Unexpected response: '%v'", result)
}
if !strings.Contains(detail, "is missing") {
t.Errorf("Unexpected response: '%v'", detail)
}
}