-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
48 lines (41 loc) · 1.16 KB
/
config_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
package server_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/ungive/loon/pkg/server"
)
func Test_validating_constraints_fails_when_an_accepted_content_type_has_parameters(t *testing.T) {
c := newConfigConstraints()
c.AcceptedContentTypes =
append(c.AcceptedContentTypes, "text/html; charset=utf-8")
err := c.Validate()
assert.NotNil(t, err)
}
func Test_validating_constraints_fails_when_a_content_type_contains_spaces(t *testing.T) {
c := newConfigConstraints()
c.AcceptedContentTypes =
append(c.AcceptedContentTypes, " text/html")
err := c.Validate()
assert.NotNil(t, err)
}
func Test_validating_constraints_fails_when_a_content_type_is_not_all_lowercase(t *testing.T) {
c := newConfigConstraints()
c.AcceptedContentTypes =
append(c.AcceptedContentTypes, "text/HTML")
err := c.Validate()
assert.NotNil(t, err)
}
func newConfigConstraints() *server.ProtocolConstraints {
return &server.ProtocolConstraints{
ChunkSize: 128,
MaxContentSize: 128,
AcceptedContentTypes: []string{
"text/html",
},
CacheDuration: durationPtr(time.Duration(0)),
}
}
func durationPtr(v time.Duration) *time.Duration {
return &v
}