Fix linter err

This commit is contained in:
Vladimir Zhukov 2023-10-30 14:27:13 +03:00
parent 1ea0e648da
commit 9f02baf15c
4 changed files with 3102 additions and 3075 deletions

View file

@ -148,19 +148,13 @@ func (a ingAnnotations) parseTimeout(name string) (string, error) {
return "0", errors.NewInvalidAnnotationContent(name, val)
}
setUnits, err := regexp.Compile(`(\d+)(s|ms)?$`)
if err != nil {
return "0", errors.NewInvalidAnnotationContent(name, val)
}
setUnits := regexp.MustCompile(`\d+s|ms$`)
if setUnits.MatchString(s) {
return s, nil
}
noUnits, err := regexp.Compile(`\d+$`)
if err != nil {
return "0", errors.NewInvalidAnnotationContent(name, val)
}
noUnits := regexp.MustCompile(`\d+$`)
if noUnits.MatchString(s) {
return fmt.Sprintf("%ss", s), nil

View file

@ -252,3 +252,36 @@ func TestStringToURL(t *testing.T) {
}
}
}
func TestStringToSecond(t *testing.T) {
ing := buildIngress()
tests := []struct {
name string
field string
value string
exp string
}{
{"valid_10", "string", "10", "10s"},
{"valid_20s", "string", "20s", "20s"},
{"valid_30s", "string", " 30s ", "30s"},
}
data := map[string]string{}
ing.SetAnnotations(data)
for _, i := range tests {
data[GetAnnotationWithPrefix(i.field)] = i.value
f, err := GetTimeoutAnnotation(i.field, ing, nil)
if err != nil {
t.Errorf("expected error but GetTimeoutAnnotation retuned err")
}
if f != i.exp {
t.Errorf("%v: expected \"%v\" but \"%v\" was returned", i.name, i.exp, f)
}
delete(data, i.field)
}
}

View file

@ -32,7 +32,7 @@ const (
off = "off"
proxyHTTPVersion = "1.0"
proxyMaxTempFileSize = "128k"
ProxyConnectTimeout = "1"
ProxyConnectTimeout = "1s"
ProxySendTimeout = "15s"
ProxyReadTimeout = "20s"
)
@ -130,7 +130,7 @@ func TestProxy(t *testing.T) {
t.Fatalf("expected a Config type")
}
if p.ConnectTimeout != ProxyConnectTimeout {
t.Errorf("expected 1 as connect-timeout but returned %v", p.ConnectTimeout)
t.Errorf("expected 1s as connect-timeout but returned %v", p.ConnectTimeout)
}
if p.SendTimeout != ProxySendTimeout {
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)
@ -252,8 +252,8 @@ func TestProxyWithNoAnnotation(t *testing.T) {
if !ok {
t.Fatalf("expected a Config type")
}
if p.ConnectTimeout != "10s" {
t.Errorf("expected 10s as connect-timeout but returned %v", p.ConnectTimeout)
if p.ConnectTimeout != "1s" {
t.Errorf("expected 1s as connect-timeout but returned %v", p.ConnectTimeout)
}
if p.SendTimeout != ProxySendTimeout {
t.Errorf("expected 15s as send-timeout but returned %v", p.SendTimeout)

File diff suppressed because it is too large Load diff