traefik/types/types_test.go

96 lines
1.9 KiB
Go
Raw Normal View History

2017-06-13 00:48:21 +00:00
package types
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHeaders_ShouldReturnFalseWhenNotHasCustomHeadersDefined(t *testing.T) {
headers := Headers{}
assert.False(t, headers.HasCustomHeadersDefined())
}
func TestHeaders_ShouldReturnTrueWhenHasCustomHeadersDefined(t *testing.T) {
headers := Headers{}
headers.CustomRequestHeaders = map[string]string{
"foo": "bar",
}
assert.True(t, headers.HasCustomHeadersDefined())
}
func TestHeaders_ShouldReturnFalseWhenNotHasSecureHeadersDefined(t *testing.T) {
headers := Headers{}
assert.False(t, headers.HasSecureHeadersDefined())
}
func TestHeaders_ShouldReturnTrueWhenHasSecureHeadersDefined(t *testing.T) {
headers := Headers{}
headers.SSLRedirect = true
assert.True(t, headers.HasSecureHeadersDefined())
}
2018-03-14 13:12:04 +00:00
func TestNewHTTPCodeRanges(t *testing.T) {
testCases := []struct {
desc string
strBlocks []string
expected HTTPCodeRanges
errExpected bool
}{
{
desc: "Should return 2 code range",
strBlocks: []string{
"200-500",
"502",
},
expected: HTTPCodeRanges{[2]int{200, 500}, [2]int{502, 502}},
errExpected: false,
},
{
desc: "Should return 2 code range",
strBlocks: []string{
"200-500",
"205",
},
expected: HTTPCodeRanges{[2]int{200, 500}, [2]int{205, 205}},
errExpected: false,
},
{
desc: "invalid code range",
strBlocks: []string{
"200-500",
"aaa",
},
expected: nil,
errExpected: true,
},
{
desc: "invalid code range nil",
strBlocks: nil,
expected: nil,
errExpected: false,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
actual, err := NewHTTPCodeRanges(test.strBlocks)
assert.Equal(t, test.expected, actual)
if test.errExpected {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}