Skip to content

Commit

Permalink
wip: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 7, 2024
1 parent 6970530 commit 3f9d9d0
Show file tree
Hide file tree
Showing 30 changed files with 832 additions and 510 deletions.
9 changes: 7 additions & 2 deletions internal/transport/http/proxy_test.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/go-git/go-git/v5/internal/transport/http/test"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"

. "gopkg.in/check.v1"
)
Expand Down Expand Up @@ -43,13 +44,17 @@ func (s *ProxySuite) TestAdvertisedReferences(c *C) {
c.Assert(err, IsNil)
endpoint.InsecureSkipTLS = true

st := memory.NewStorage()
client := http.DefaultTransport
session, err := client.NewUploadPackSession(endpoint, nil)
session, err := client.NewSession(st, endpoint, nil)
c.Assert(err, IsNil)
conn, err := session.Handshake(context.Background(), false)
c.Assert(err, IsNil)
defer func() { c.Assert(conn.Close(), IsNil) }()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
info, err := session.AdvertisedReferencesContext(ctx)
info, err := conn.GetRemoteRefs(ctx)
c.Assert(err, IsNil)
c.Assert(info, NotNil)
proxyUsed := atomic.LoadInt32(&proxiedRequests) > 0
Expand Down
17 changes: 11 additions & 6 deletions internal/transport/ssh/test/proxy_test.go
Expand Up @@ -12,8 +12,11 @@ import (

"github.com/armon/go-socks5"
"github.com/gliderlabs/ssh"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/plumbing/transport"
ggssh "github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/go-git/go-git/v5/storage"
"github.com/go-git/go-git/v5/storage/filesystem"

fixtures "github.com/go-git/go-git-fixtures/v4"
stdssh "golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -65,24 +68,26 @@ func (s *ProxyEnvSuite) TestCommand(c *C) {
return &ggssh.Password{User: user}, nil
}

ep := s.prepareRepository(c, fixtures.Basic().One(), "basic.git")
st, ep := s.prepareRepository(c, fixtures.Basic().One(), "basic.git")
c.Assert(err, IsNil)

client := ggssh.NewTransport(&stdssh.ClientConfig{
HostKeyCallback: stdssh.InsecureIgnoreHostKey(),
})
r, err := client.NewUploadPackSession(ep, nil)
r, err := client.NewSession(st, ep, nil)
c.Assert(err, IsNil)
defer func() { c.Assert(r.Close(), IsNil) }()
conn, err := r.Handshake(context.Background(), false)
c.Assert(err, IsNil)
defer func() { c.Assert(conn.Close(), IsNil) }()

info, err := r.AdvertisedReferences()
info, err := conn.GetRemoteRefs(context.Background())
c.Assert(err, IsNil)
c.Assert(info, NotNil)
proxyUsed := atomic.LoadInt32(&socksProxiedRequests) > 0
c.Assert(proxyUsed, Equals, true)
}

func (s *ProxyEnvSuite) prepareRepository(c *C, f *fixtures.Fixture, name string) *transport.Endpoint {
func (s *ProxyEnvSuite) prepareRepository(c *C, f *fixtures.Fixture, name string) (storage.Storer, *transport.Endpoint) {
fs := f.DotGit()

err := fixtures.EnsureIsBare(fs)
Expand All @@ -92,7 +97,7 @@ func (s *ProxyEnvSuite) prepareRepository(c *C, f *fixtures.Fixture, name string
err = os.Rename(fs.Root(), path)
c.Assert(err, IsNil)

return s.newEndpoint(c, name)
return filesystem.NewStorage(fs, cache.NewObjectLRUDefault()), s.newEndpoint(c, name)
}

func (s *ProxyEnvSuite) newEndpoint(c *C, name string) *transport.Endpoint {
Expand Down

0 comments on commit 3f9d9d0

Please sign in to comment.