Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/cli/provider_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1677,8 +1677,14 @@ func routeConfiguredProvider(cfg *Config) error {
return nil
}

const defaultRuntimeHTTPTimeout = 60 * time.Second

func defaultRuntimeHTTP() *http.Client {
return &http.Client{Timeout: defaultRuntimeHTTPTimeout}
}

func runtimeForApp(a App) Runtime {
return Runtime{Stdout: a.Stdout, Stderr: a.Stderr, Clock: realClock{}, Exec: execCommandRunner{}}
return Runtime{Stdout: a.Stdout, Stderr: a.Stderr, Clock: realClock{}, HTTP: defaultRuntimeHTTP(), Exec: execCommandRunner{}}
}

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/provider_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func RuntimeForProviderOperation(stderr io.Writer) Runtime {
if stderr == nil {
stderr = io.Discard
}
return Runtime{Stdout: io.Discard, Stderr: stderr, Clock: realClock{}, Exec: execCommandRunner{}}
return Runtime{Stdout: io.Discard, Stderr: stderr, Clock: realClock{}, HTTP: defaultRuntimeHTTP(), Exec: execCommandRunner{}}
}

// ProviderSelectionIsAuthoritativeRoute reports whether cfg names an exact
Expand Down
27 changes: 27 additions & 0 deletions internal/cli/runtime_http_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cli

import (
"io"
"testing"
"time"
)

func TestRuntimeForAppSetsTimedHTTPClient(t *testing.T) {
rt := runtimeForApp(App{})
if rt.HTTP == nil {
t.Fatal("runtimeForApp HTTP is nil")
}
if got, want := rt.HTTP.Timeout, 60*time.Second; got != want {
t.Fatalf("runtimeForApp HTTP Timeout = %v, want %v", got, want)
}
}

func TestRuntimeForProviderOperationSetsTimedHTTPClient(t *testing.T) {
rt := RuntimeForProviderOperation(io.Discard)
if rt.HTTP == nil {
t.Fatal("RuntimeForProviderOperation HTTP is nil")
}
if got, want := rt.HTTP.Timeout, 60*time.Second; got != want {
t.Fatalf("RuntimeForProviderOperation HTTP Timeout = %v, want %v", got, want)
}
}