-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathx-powered-by_test.go
78 lines (63 loc) · 1.84 KB
/
x-powered-by_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
package helmet
import (
"testing"
)
func TestXPoweredBy_NewXPoweredBy(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
hide bool
replacement string
}{
{name: "Empty", hide: false, replacement: ""},
{name: "Hide", hide: true, replacement: ""},
{name: "Replacement", hide: false, replacement: "PHP 4.2.0"},
{name: "Empty, Replacement", hide: true, replacement: "PHP 4.2.0"},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
xpb := NewXPoweredBy(tc.hide, tc.replacement)
if xpb.Hide != tc.hide {
t.Errorf("Incorrect Hide\tExpected: %t\tActual: %t\n", tc.hide, xpb.Hide)
}
if xpb.Replacement != tc.replacement {
t.Errorf("Incorrect Replacement\tExpected: %s\tActual: %s\n", tc.replacement, xpb.Replacement)
}
})
}
}
func TestXPoweredBy_EmptyXPoweredBy(t *testing.T) {
t.Parallel()
xpb := EmptyXPoweredBy()
if xpb.Hide != false {
t.Errorf("Hide should be false\tActual: %t\n", xpb.Hide)
}
if xpb.Replacement != "" {
t.Errorf("Replacement should be empty\tActual: %s\n", xpb.Replacement)
}
}
func TestXPoweredBy_Empty(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
xPoweredBy *XPoweredBy
expectedEmpty bool
}{
{name: "Empty", xPoweredBy: EmptyXPoweredBy(), expectedEmpty: true},
{name: "Hide", xPoweredBy: NewXPoweredBy(true, ""), expectedEmpty: false},
{name: "Replacement", xPoweredBy: NewXPoweredBy(false, "PHP 4.2.0"), expectedEmpty: false},
{name: "Hide, Replacement", xPoweredBy: NewXPoweredBy(true, "PHP 4.2.0"), expectedEmpty: false},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
exists := tc.xPoweredBy.Empty()
if exists != tc.expectedEmpty {
t.Errorf("Expected: %t\tActual: %t\n", tc.expectedEmpty, exists)
}
})
}
}