1
0
mirror of https://github.com/nginxinc/nginx-prometheus-exporter.git synced 2025-08-08 05:02:04 +03:00

Fix nginxRetries and timeout accepts a negative value

* Bug introduced in: b499ca793a
This commit is contained in:
Dean Coakley
2019-04-03 11:49:13 +01:00
committed by GitHub
parent 4ef2b34672
commit d35d429dcc
2 changed files with 97 additions and 23 deletions

View File

@@ -11,7 +11,7 @@ func TestCreateClientWithRetries(t *testing.T) {
type args struct {
client interface{}
err error
retries int
retries uint
retryInterval time.Duration
}
@@ -81,3 +81,43 @@ func TestCreateClientWithRetries(t *testing.T) {
})
}
}
func TestParsePositiveDuration(t *testing.T) {
tests := []struct {
name string
testInput string
want positiveDuration
wantErr bool
}{
{
"ParsePositiveDuration returns a positiveDuration",
"15ms",
positiveDuration{15 * time.Millisecond},
false,
},
{
"ParsePositiveDuration returns error for trying to parse negative value",
"-15ms",
positiveDuration{},
true,
},
{
"ParsePositiveDuration returns error for trying to parse empty string",
"",
positiveDuration{},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parsePositiveDuration(tt.testInput)
if (err != nil) != tt.wantErr {
t.Errorf("parsePositiveDuration() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("parsePositiveDuration() = %v, want %v", got, tt.want)
}
})
}
}