Skip to content

Commit

Permalink
test: add gh.TestRunInteractiveContextCanceled
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Stenger committed Mar 27, 2023
1 parent 59fd6f5 commit b964df6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions gh_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package gh

import (
"context"
"fmt"
"net/http"
"os"
"strings"
"testing"
"time"

"github.com/cli/go-gh/pkg/api"
"github.com/cli/go-gh/pkg/config"
Expand All @@ -30,6 +32,18 @@ func TestHelperProcess(t *testing.T) {
os.Exit(0)
}

func TestHelperProcessLongRunning(t *testing.T) {
if os.Getenv("GH_WANT_HELPER_PROCESS") != "1" {
return
}
args := os.Args[3:]
fmt.Fprintf(os.Stdout, "%v", args)
fmt.Fprint(os.Stderr, "going to sleep...")
time.Sleep(10 * time.Second)
fmt.Fprint(os.Stderr, "...going to exit")
os.Exit(0)
}

func TestRun(t *testing.T) {
stdOut, stdErr, err := run(os.Args[0],
[]string{"GH_WANT_HELPER_PROCESS=1"},
Expand All @@ -48,6 +62,16 @@ func TestRunError(t *testing.T) {
assert.Equal(t, "process exited with error", stdErr.String())
}

func TestRunInteractiveContextCanceled(t *testing.T) {
// pass current time to ensure that deadline has already passed
ctx, cancel := context.WithDeadline(context.Background(), time.Now())
cancel()
err := runInteractive(ctx, os.Args[0],
[]string{"GH_WANT_HELPER_PROCESS=1"},
"-test.run=TestHelperProcessLongRunning", "--", "gh", "issue", "list")
assert.EqualError(t, err, "gh execution failed: context deadline exceeded")
}

func TestRESTClient(t *testing.T) {
stubConfig(t, testConfig())
t.Cleanup(gock.Off)
Expand Down

0 comments on commit b964df6

Please sign in to comment.