@@ -2,8 +2,10 @@ package diff
22
33import (
44 "bytes"
5+ "io"
56 "io/ioutil"
67 "net/http"
8+ "os"
79 "testing"
810
911 "github.com/cli/cli/context"
@@ -131,8 +133,13 @@ func TestPRDiff_notty(t *testing.T) {
131133}
132134
133135func TestPRDiff_tty (t * testing.T ) {
136+ pager := os .Getenv ("PAGER" )
134137 http := & httpmock.Registry {}
135- defer http .Verify (t )
138+ defer func () {
139+ os .Setenv ("PAGER" , pager )
140+ http .Verify (t )
141+ }()
142+ os .Setenv ("PAGER" , "" )
136143 http .StubResponse (200 , bytes .NewBufferString (`
137144 { "data": { "repository": { "pullRequests": { "nodes": [
138145 { "url": "https://github.com/OWNER/REPO/pull/123",
@@ -149,6 +156,38 @@ func TestPRDiff_tty(t *testing.T) {
149156 assert .Contains (t , output .String (), "\x1b [32m+site: bin/gh\x1b [m" )
150157}
151158
159+ func TestPRDiff_pager (t * testing.T ) {
160+ realRunPager := runPager
161+ pager := os .Getenv ("PAGER" )
162+ http := & httpmock.Registry {}
163+ defer func () {
164+ runPager = realRunPager
165+ os .Setenv ("PAGER" , pager )
166+ http .Verify (t )
167+ }()
168+ runPager = func (pager string , diff io.Reader , out io.Writer ) error {
169+ _ , err := io .Copy (out , diff )
170+ return err
171+ }
172+ os .Setenv ("PAGER" , "fakepager" )
173+ http .StubResponse (200 , bytes .NewBufferString (`
174+ { "data": { "repository": { "pullRequests": { "nodes": [
175+ { "url": "https://github.com/OWNER/REPO/pull/123",
176+ "number": 123,
177+ "id": "foobar123",
178+ "headRefName": "feature",
179+ "baseRefName": "master" }
180+ ] } } } }` ))
181+ http .StubResponse (200 , bytes .NewBufferString (testDiff ))
182+ output , err := runCommand (http , nil , true , "" )
183+ if err != nil {
184+ t .Fatalf ("unexpected error: %s" , err )
185+ }
186+ if diff := cmp .Diff (testDiff , output .String ()); diff != "" {
187+ t .Errorf ("command output did not match:\n %s" , diff )
188+ }
189+ }
190+
152191const testDiff = `diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml
153192index 73974448..b7fc0154 100644
154193--- a/.github/workflows/releases.yml
0 commit comments