55 "regexp"
66 "strings"
77 "testing"
8+ "time"
89
910 "github.com/cli/cli/context"
1011 "github.com/cli/cli/utils"
@@ -23,7 +24,7 @@ func TestRepoFork_already_forked(t *testing.T) {
2324 }
2425 http := initFakeHTTP ()
2526 http .StubRepoResponse ("OWNER" , "REPO" )
26- defer http .StubWithFixture (200 , "repo .json" )()
27+ defer http .StubWithFixture (200 , "forkResult .json" )()
2728
2829 _ , err := RunCommand (repoForkCmd , "repo fork --remote=false" )
2930 if err == nil {
@@ -34,11 +35,21 @@ func TestRepoFork_already_forked(t *testing.T) {
3435 }
3536}
3637
38+ func stubSince (d time.Duration ) func () {
39+ originalSince := Since
40+ Since = func (t time.Time ) time.Duration {
41+ return d
42+ }
43+ return func () {
44+ Since = originalSince
45+ }
46+ }
47+
3748func TestRepoFork_in_parent (t * testing.T ) {
3849 initBlankContext ("OWNER/REPO" , "master" )
50+ defer stubSince (2 * time .Second )()
3951 http := initFakeHTTP ()
4052 http .StubRepoResponse ("OWNER" , "REPO" )
41- defer http .StubWithFixture (200 , "repoNotFound.json" )()
4253 defer http .StubWithFixture (200 , "forkResult.json" )()
4354
4455 output , err := RunCommand (repoForkCmd , "repo fork --remote=false" )
@@ -75,8 +86,8 @@ func TestRepoFork_outside(t *testing.T) {
7586 }
7687 for _ , tt := range tests {
7788 t .Run (tt .name , func (t * testing.T ) {
89+ defer stubSince (2 * time .Second )()
7890 http := initFakeHTTP ()
79- defer http .StubWithFixture (200 , "repoNotFound.json" )()
8091 defer http .StubWithFixture (200 , "forkResult.json" )()
8192
8293 output , err := RunCommand (repoForkCmd , tt .args )
@@ -101,9 +112,9 @@ func TestRepoFork_outside(t *testing.T) {
101112
102113func TestRepoFork_in_parent_yes (t * testing.T ) {
103114 initBlankContext ("OWNER/REPO" , "master" )
115+ defer stubSince (2 * time .Second )()
104116 http := initFakeHTTP ()
105117 http .StubRepoResponse ("OWNER" , "REPO" )
106- defer http .StubWithFixture (200 , "repoNotFound.json" )()
107118 defer http .StubWithFixture (200 , "forkResult.json" )()
108119
109120 var seenCmds []* exec.Cmd
@@ -141,8 +152,8 @@ func TestRepoFork_in_parent_yes(t *testing.T) {
141152}
142153
143154func TestRepoFork_outside_yes (t * testing.T ) {
155+ defer stubSince (2 * time .Second )()
144156 http := initFakeHTTP ()
145- defer http .StubWithFixture (200 , "repoNotFound.json" )()
146157 defer http .StubWithFixture (200 , "forkResult.json" )()
147158
148159 var seenCmd * exec.Cmd
@@ -173,8 +184,8 @@ func TestRepoFork_outside_yes(t *testing.T) {
173184}
174185
175186func TestRepoFork_outside_survey_yes (t * testing.T ) {
187+ defer stubSince (2 * time .Second )()
176188 http := initFakeHTTP ()
177- defer http .StubWithFixture (200 , "repoNotFound.json" )()
178189 defer http .StubWithFixture (200 , "forkResult.json" )()
179190
180191 var seenCmd * exec.Cmd
@@ -212,8 +223,8 @@ func TestRepoFork_outside_survey_yes(t *testing.T) {
212223}
213224
214225func TestRepoFork_outside_survey_no (t * testing.T ) {
226+ defer stubSince (2 * time .Second )()
215227 http := initFakeHTTP ()
216- defer http .StubWithFixture (200 , "repoNotFound.json" )()
217228 defer http .StubWithFixture (200 , "forkResult.json" )()
218229
219230 cmdRun := false
@@ -251,9 +262,9 @@ func TestRepoFork_outside_survey_no(t *testing.T) {
251262
252263func TestRepoFork_in_parent_survey_yes (t * testing.T ) {
253264 initBlankContext ("OWNER/REPO" , "master" )
265+ defer stubSince (2 * time .Second )()
254266 http := initFakeHTTP ()
255267 http .StubRepoResponse ("OWNER" , "REPO" )
256- defer http .StubWithFixture (200 , "repoNotFound.json" )()
257268 defer http .StubWithFixture (200 , "forkResult.json" )()
258269
259270 var seenCmds []* exec.Cmd
@@ -299,9 +310,9 @@ func TestRepoFork_in_parent_survey_yes(t *testing.T) {
299310
300311func TestRepoFork_in_parent_survey_no (t * testing.T ) {
301312 initBlankContext ("OWNER/REPO" , "master" )
313+ defer stubSince (2 * time .Second )()
302314 http := initFakeHTTP ()
303315 http .StubRepoResponse ("OWNER" , "REPO" )
304- defer http .StubWithFixture (200 , "repoNotFound.json" )()
305316 defer http .StubWithFixture (200 , "forkResult.json" )()
306317
307318 cmdRun := false
0 commit comments