add access log filter for retry attempts

This commit is contained in:
Marco Jantke 2018-03-23 09:28:03 +01:00 committed by Traefiker Bot
parent 5792a19b97
commit c762b9bb2e
6 changed files with 116 additions and 28 deletions

View file

@ -1,6 +1,7 @@
package types
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
@ -93,3 +94,45 @@ func TestNewHTTPCodeRanges(t *testing.T) {
})
}
}
func TestHTTPCodeRanges_Contains(t *testing.T) {
testCases := []struct {
strBlocks []string
statusCode int
contains bool
}{
{
strBlocks: []string{"200-299"},
statusCode: 200,
contains: true,
},
{
strBlocks: []string{"200"},
statusCode: 200,
contains: true,
},
{
strBlocks: []string{"201"},
statusCode: 200,
contains: false,
},
{
strBlocks: []string{"200-299", "500-599"},
statusCode: 400,
contains: false,
},
}
for _, test := range testCases {
test := test
testName := fmt.Sprintf("%q contains %d", test.strBlocks, test.statusCode)
t.Run(testName, func(t *testing.T) {
t.Parallel()
httpCodeRanges, err := NewHTTPCodeRanges(test.strBlocks)
assert.NoError(t, err)
assert.Equal(t, test.contains, httpCodeRanges.Contains(test.statusCode))
})
}
}