8000 add more tests for context wiring · go-git/go-git@bbd4c4f · GitHub
[go: up one dir, main page]

Skip to content

Commit bbd4c4f

Browse files
committed
add more tests for context wiring
1 parent 44faab6 commit bbd4c4f

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

plumbing/transport/http/upload_pack_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package http
22

33
import (
4+
"context"
45
"fmt"
56
"io/ioutil"
7+
"net/url"
68
"os"
79
"path/filepath"
810

@@ -103,3 +105,32 @@ func (s *UploadPackSuite) TestAdvertisedReferencesRedirectSchema(c *C) {
103105
url := session.(*upSession).endpoint.String()
104106
c.Assert(url, Equals, "https://github.com/git-fixtures/basic")
105107
}
108+
109+
func (s *UploadPackSuite) TestAdvertisedReferencesContext(c *C) {
110+
ctx, cancel := context.WithCancel(context.Background())
111+
defer cancel()
112+
endpoint, _ := transport.NewEndpoint("http://github.com/git-fixtures/basic")
113+
114+
session, err := s.Client.NewUploadPackSession(endpoint, s.EmptyAuth)
115+
c.Assert(err, IsNil)
116+
117+
info, err := session.AdvertisedReferencesContext(ctx)
118+
c.Assert(err, IsNil)
119+
c.Assert(info, NotNil)
120+
121+
url := session.(*upSession).endpoint.String()
122+
c.Assert(url, Equals, "https://github.com/git-fixtures/basic")
123+
}
124+
125+
func (s *UploadPackSuite) TestAdvertisedReferencesContextCanceled(c *C) {
126+
ctx, cancel := context.WithCancel(context.Background())
127+
cancel()
128+
endpoint, _ := transport.NewEndpoint("http://github.com/git-fixtures/basic")
129+
130+
session, err := s.Client.NewUploadPackSession(endpoint, s.EmptyAuth)
131+
c.Assert(err, IsNil)
132+
133+
info, err := session.AdvertisedReferencesContext(ctx)
134+
c.Assert(err, DeepEquals, &url.Error{Op: "Get", URL: "http://github.com/git-fixtures/basic/info/refs?service=git-upload-pack", Err: context.Canceled})
135+
c.Assert(info, IsNil)
136+
}

remote_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ func (s *RemoteSuite) TestFetchContext(c *C) {
154154
URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())},
155155
})
156156

157+
ctx, cancel := context.WithCancel(context.Background())
158+
defer cancel()
159+
160+
err := r.FetchContext(ctx, &FetchOptions{
161+
RefSpecs: []config.RefSpec{
162+
config.RefSpec("+refs/heads/master:refs/remotes/origin/master"),
163+
},
164+
})
165+
c.Assert(err, IsNil)
166+
}
167+
168+
func (s *RemoteSuite) TestFetchContextCanceled(c *C) {
169+
r := NewRemote(memory.NewStorage(), &config.RemoteConfig{
170+
URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())},
171+
})
172+
157173
ctx, cancel := context.WithCancel(context.Background())
158174
cancel()
159175

@@ -478,6 +494,35 @@ func (s *RemoteSuite) TestPushContext(c *C) {
478494
URLs: []string{url},
479495
})
480496

497+
ctx, cancel := context.WithCancel(context.Background())
498+
defer cancel()
499+
500+
numGoroutines := runtime.NumGoroutine()
501+
502+
err = r.PushContext(ctx, &PushOptions{
503+
RefSpecs: []config.RefSpec{"refs/tags/*:refs/tags/*"},
504+
})
505+
c.Assert(err, IsNil)
506+
507+
// let the goroutine from pushHashes finish and check that the number of
508+
// goroutines is the same as before
509+
time.Sleep(100 * time.Millisecond)
510+
c.Assert(runtime.NumGoroutine(), Equals, numGoroutines)
511+
}
512+
513+
func (s *RemoteSuite) TestPushContextCanceled(c *C) {
514+
url := c.MkDir()
515+
_, err := PlainInit(url, true)
516+
c.Assert(err, IsNil)
517+
518+
fs := fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit()
519+
sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
520+
521+
r := NewRemote(sto, &config.RemoteConfig{
522+
Name: DefaultRemoteName,
523+
URLs: []string{url},
524+
})
525+
481526
ctx, cancel := context.WithCancel(context.Background())
482527
cancel()
483528

0 commit comments

Comments
 (0)
0