diff options
Diffstat (limited to 'client/go')
-rw-r--r-- | client/go/internal/admin/deploy/curl.go | 2 | ||||
-rw-r--r-- | client/go/internal/curl/curl.go | 13 | ||||
-rw-r--r-- | client/go/internal/curl/curl_test.go | 4 |
3 files changed, 13 insertions, 6 deletions
diff --git a/client/go/internal/admin/deploy/curl.go b/client/go/internal/admin/deploy/curl.go index ca044128e93..0ce1305226f 100644 --- a/client/go/internal/admin/deploy/curl.go +++ b/client/go/internal/admin/deploy/curl.go @@ -89,7 +89,7 @@ func runCurl(cmd *curl.Command, stdout io.Writer) error { if err != nil { if ee, ok := err.(*exec.ExitError); ok { if ee.ProcessState.ExitCode() == 7 { - return fmt.Errorf("HTTP request failed. Could not connect to %s", cmd.GetUrlPrefix()) + return fmt.Errorf("HTTP request failed. Could not connect to %s", cmd.URLPrefix()) } } return fmt.Errorf("HTTP request failed with curl %s", err.Error()) diff --git a/client/go/internal/curl/curl.go b/client/go/internal/curl/curl.go index 3938938d2f3..e41f48840a2 100644 --- a/client/go/internal/curl/curl.go +++ b/client/go/internal/curl/curl.go @@ -7,9 +7,10 @@ import ( "os/exec" "runtime" "sort" + "strconv" + "time" "github.com/alessio/shellescape" - "github.com/vespa-engine/vespa/client/go/internal/util" ) type header struct { @@ -23,6 +24,7 @@ type Command struct { PrivateKey string CaCertificate string Certificate string + Timeout time.Duration bodyFile string bodyInput io.Reader url *url.URL @@ -30,20 +32,20 @@ type Command struct { rawArgs []string } -func (c *Command) GetUrlPrefix() string { +func (c *Command) URLPrefix() string { return c.url.Scheme + "://" + c.url.Host } func (c *Command) WithBodyFile(fn string) { if c.bodyInput != nil { - util.JustExitMsg("cannot use both WithBodyFile and WithBodyInput") + panic("cannot use both WithBodyFile and WithBodyInput") } c.bodyFile = fn } func (c *Command) WithBodyInput(r io.Reader) { if c.bodyFile != "" { - util.JustExitMsg("cannot use both WithBodyFile and WithBodyInput") + panic("cannot use both WithBodyFile and WithBodyInput") } c.bodyInput = r } @@ -62,6 +64,9 @@ func (c *Command) Args() []string { if c.Method != "" { args = append(args, "-X", c.Method) } + if c.Timeout > 0 { + args = append(args, "-m", strconv.FormatInt(int64(c.Timeout.Seconds()), 10)) + } sort.Slice(c.headers, func(i, j int) bool { return c.headers[i].key < c.headers[j].key }) for _, header := range c.headers { args = append(args, "-H", header.key+": "+header.value) diff --git a/client/go/internal/curl/curl_test.go b/client/go/internal/curl/curl_test.go index 61354c408d2..83bb7e72dbe 100644 --- a/client/go/internal/curl/curl_test.go +++ b/client/go/internal/curl/curl_test.go @@ -3,6 +3,7 @@ package curl import ( "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -13,10 +14,11 @@ func TestPost(t *testing.T) { require.Nil(t, err) c.PrivateKey = "key.pem" c.Certificate = "cert.pem" + c.Timeout = time.Minute c.WithBodyFile("file.json") c.Header("Content-Type", "application/json") - assert.Equal(t, "curl --key key.pem --cert cert.pem -X POST -H 'Content-Type: application/json' --data-binary @file.json https://example.com", c.String()) + assert.Equal(t, "curl --key key.pem --cert cert.pem -X POST -m 60 -H 'Content-Type: application/json' --data-binary @file.json https://example.com", c.String()) } func TestGet(t *testing.T) { |