Skip to content

Commit

Permalink
handle negative duration case
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
  • Loading branch information
atoulme committed Dec 24, 2021
1 parent 8581ce9 commit e58d106
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions daemon/logger/splunk/splunk.go
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/docker/docker/daemon/logger/loggerutils"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/urlutil"
"github.com/docker/docker/vendor/github.com/pkg/errors"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -236,6 +237,9 @@ func New(info logger.Info) (logger.Logger, error) {
if err != nil {
return nil, err
}
if value < 0 {
return nil, errors.Errorf("negative timeout provided: %v", value)
}
timeout = value
}

Expand Down
21 changes: 21 additions & 0 deletions daemon/logger/splunk/splunk_test.go
Expand Up @@ -1449,3 +1449,24 @@ func TestCustomHttpTimeout(t *testing.T) {
t.Fatal(err)
}
}

func TestNegativeTimeout(t *testing.T) {
info := logger.Info{
Config: map[string]string{
splunkURLKey: "http://localhost:8000",
splunkTokenKey: "1234",
splunkHTTPTimeout: "-100ms",
},
ContainerID: "containeriid",
ContainerName: "/container_name",
ContainerImageID: "contaimageid",
ContainerImageName: "container_image_name",
}
_, err := New(info)
if err == nil {
t.Fatal("no error")
}
if err.Error() != "negative timeout provided: -100ms" {
t.Fatalf("unexpected error message: %s", err.Error())
}
}

0 comments on commit e58d106

Please sign in to comment.