Skip to content

Commit

Permalink
Add the option of timeout and change the default timeout 10s.
Browse files Browse the repository at this point in the history
  • Loading branch information
fourdollars committed Jul 5, 2024
1 parent 5dc2eca commit 16c6eeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lp-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (lp LaunchpadAPI) QueryProcess(req *http.Request, args []string) {

func (lp LaunchpadAPI) DoProcess(req *http.Request) (string, error) {
client := &http.Client{
Timeout: 5 * time.Second,
Timeout: *timeout,
}
resp, err := client.Do(req)
if err != nil {
Expand Down Expand Up @@ -424,6 +424,7 @@ var key = flag.String("key", "System-wide: golang (https://github.com/fourdollar
var lpAPI = "https://api.launchpad.net/devel/"
var output = flag.String("output", "", "Specify the output file.")
var staging = flag.Bool("staging", false, "Use Launchpad staging server.")
var timeout = flag.Duration("timeout", 10 * time.Second, "Timeout for Launchpad API requests.")

func main() {
flag.Parse()
Expand Down
14 changes: 14 additions & 0 deletions lp-api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func Test_stagingAPI(t *testing.T) {
os.Args = backupArgs
}

func Test_timeout10s(t *testing.T) {
os.Clearenv()
os.Setenv("LAUNCHPAD_TOKEN", "::")
backupArgs := os.Args

os.Args = append(os.Args, "-debug")
os.Args = append(os.Args, "-timeout")
os.Args = append(os.Args, "10s")
os.Args = append(os.Args, "get")
os.Args = append(os.Args, "https://api.launchpad.net/devel/bugs/1")
main()
os.Args = backupArgs
}

func Test_download(t *testing.T) {
t.Cleanup(func() {
os.Remove("data")
Expand Down

0 comments on commit 16c6eeb

Please sign in to comment.