Fix linter err
This commit is contained in:
parent
5a354bf4dc
commit
1ea0e648da
2 changed files with 31 additions and 20 deletions
|
@ -144,16 +144,24 @@ func (a ingAnnotations) parseTimeout(name string) (string, error) {
|
||||||
val, ok := a[name]
|
val, ok := a[name]
|
||||||
if ok {
|
if ok {
|
||||||
s := normalizeString(val)
|
s := normalizeString(val)
|
||||||
if len(s) == 0 {
|
if s == "" {
|
||||||
|
return "0", errors.NewInvalidAnnotationContent(name, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
setUnits, err := regexp.Compile(`(\d+)(s|ms)?$`)
|
||||||
|
if err != nil {
|
||||||
return "0", errors.NewInvalidAnnotationContent(name, val)
|
return "0", errors.NewInvalidAnnotationContent(name, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
setUnits, _ := regexp.Compile(`(\d+)(s|ms)?$`)
|
|
||||||
if setUnits.MatchString(s) {
|
if setUnits.MatchString(s) {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
noUnits, _ := regexp.Compile(`\d+$`)
|
noUnits, err := regexp.Compile(`\d+$`)
|
||||||
|
if err != nil {
|
||||||
|
return "0", errors.NewInvalidAnnotationContent(name, val)
|
||||||
|
}
|
||||||
|
|
||||||
if noUnits.MatchString(s) {
|
if noUnits.MatchString(s) {
|
||||||
return fmt.Sprintf("%ss", s), nil
|
return fmt.Sprintf("%ss", s), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ const (
|
||||||
off = "off"
|
off = "off"
|
||||||
proxyHTTPVersion = "1.0"
|
proxyHTTPVersion = "1.0"
|
||||||
proxyMaxTempFileSize = "128k"
|
proxyMaxTempFileSize = "128k"
|
||||||
|
ProxyConnectTimeout = "1"
|
||||||
|
ProxySendTimeout = "15s"
|
||||||
|
ProxyReadTimeout = "20s"
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildIngress() *networking.Ingress {
|
func buildIngress() *networking.Ingress {
|
||||||
|
@ -83,9 +86,9 @@ type mockBackend struct {
|
||||||
|
|
||||||
func (m mockBackend) GetDefaultBackend() defaults.Backend {
|
func (m mockBackend) GetDefaultBackend() defaults.Backend {
|
||||||
return defaults.Backend{
|
return defaults.Backend{
|
||||||
ProxyConnectTimeout: "10s",
|
ProxyConnectTimeout: ProxyConnectTimeout,
|
||||||
ProxySendTimeout: "15s",
|
ProxySendTimeout: ProxySendTimeout,
|
||||||
ProxyReadTimeout: "20s",
|
ProxyReadTimeout: ProxyReadTimeout,
|
||||||
ProxyBuffersNumber: 4,
|
ProxyBuffersNumber: 4,
|
||||||
ProxyBufferSize: "10k",
|
ProxyBufferSize: "10k",
|
||||||
ProxyBodySize: "3k",
|
ProxyBodySize: "3k",
|
||||||
|
@ -103,9 +106,9 @@ func TestProxy(t *testing.T) {
|
||||||
ing := buildIngress()
|
ing := buildIngress()
|
||||||
|
|
||||||
data := map[string]string{}
|
data := map[string]string{}
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-connect-timeout")] = "1"
|
data[parser.GetAnnotationWithPrefix("proxy-connect-timeout")] = ProxyConnectTimeout
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-send-timeout")] = "15s"
|
data[parser.GetAnnotationWithPrefix("proxy-send-timeout")] = ProxySendTimeout
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "20s"
|
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = ProxyReadTimeout
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
|
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
||||||
|
@ -126,13 +129,13 @@ func TestProxy(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected a Config type")
|
t.Fatalf("expected a Config type")
|
||||||
}
|
}
|
||||||
if p.ConnectTimeout != "1" {
|
if p.ConnectTimeout != ProxyConnectTimeout {
|
||||||
t.Errorf("expected 1 as connect-timeout but returned %v", p.ConnectTimeout)
|
t.Errorf("expected 1 as connect-timeout but returned %v", p.ConnectTimeout)
|
||||||
}
|
}
|
||||||
if p.SendTimeout != "15s" {
|
if p.SendTimeout != ProxySendTimeout {
|
||||||
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)
|
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)
|
||||||
}
|
}
|
||||||
if p.ReadTimeout != "20s" {
|
if p.ReadTimeout != ProxyReadTimeout {
|
||||||
t.Errorf("expected 20s as read-timeout but returned %v", p.ReadTimeout)
|
t.Errorf("expected 20s as read-timeout but returned %v", p.ReadTimeout)
|
||||||
}
|
}
|
||||||
if p.BuffersNumber != 8 {
|
if p.BuffersNumber != 8 {
|
||||||
|
@ -171,9 +174,9 @@ func TestProxyComplex(t *testing.T) {
|
||||||
ing := buildIngress()
|
ing := buildIngress()
|
||||||
|
|
||||||
data := map[string]string{}
|
data := map[string]string{}
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-connect-timeout")] = "1"
|
data[parser.GetAnnotationWithPrefix("proxy-connect-timeout")] = ProxyConnectTimeout
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-send-timeout")] = "15s"
|
data[parser.GetAnnotationWithPrefix("proxy-send-timeout")] = ProxySendTimeout
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "20s"
|
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = ProxyReadTimeout
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
|
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
||||||
|
@ -194,13 +197,13 @@ func TestProxyComplex(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected a Config type")
|
t.Fatalf("expected a Config type")
|
||||||
}
|
}
|
||||||
if p.ConnectTimeout != "1" {
|
if p.ConnectTimeout != ProxyConnectTimeout {
|
||||||
t.Errorf("expected 1 as connect-timeout but returned %v", p.ConnectTimeout)
|
t.Errorf("expected 1 as connect-timeout but returned %v", p.ConnectTimeout)
|
||||||
}
|
}
|
||||||
if p.SendTimeout != "15s" {
|
if p.SendTimeout != ProxySendTimeout {
|
||||||
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)
|
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)
|
||||||
}
|
}
|
||||||
if p.ReadTimeout != "20s" {
|
if p.ReadTimeout != ProxyReadTimeout {
|
||||||
t.Errorf("expected 20s as read-timeout but returned %v", p.ReadTimeout)
|
t.Errorf("expected 20s as read-timeout but returned %v", p.ReadTimeout)
|
||||||
}
|
}
|
||||||
if p.BuffersNumber != 8 {
|
if p.BuffersNumber != 8 {
|
||||||
|
@ -252,10 +255,10 @@ func TestProxyWithNoAnnotation(t *testing.T) {
|
||||||
if p.ConnectTimeout != "10s" {
|
if p.ConnectTimeout != "10s" {
|
||||||
t.Errorf("expected 10s as connect-timeout but returned %v", p.ConnectTimeout)
|
t.Errorf("expected 10s as connect-timeout but returned %v", p.ConnectTimeout)
|
||||||
}
|
}
|
||||||
if p.SendTimeout != "15s" {
|
if p.SendTimeout != ProxySendTimeout {
|
||||||
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)
|
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)
|
||||||
}
|
}
|
||||||
if p.ReadTimeout != "20s" {
|
if p.ReadTimeout != ProxyReadTimeout {
|
||||||
t.Errorf("expected 20s as read-timeout but returned %v", p.ReadTimeout)
|
t.Errorf("expected 20s as read-timeout but returned %v", p.ReadTimeout)
|
||||||
}
|
}
|
||||||
if p.BuffersNumber != 4 {
|
if p.BuffersNumber != 4 {
|
||||||
|
|
Loading…
Reference in a new issue