aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/file/server_test.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-01-04 11:18:41 +0100
committerGitHub <noreply@github.com>2017-01-04 11:18:41 +0100
commit841abfb7dc640755c443432064252907e3e55c95 (patch)
tree8af69dcd3b301a10a3e493e2cd805cdec6dcaecd /plumbing/transport/file/server_test.go
parent90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (diff)
downloadgo-git-841abfb7dc640755c443432064252907e3e55c95.tar.gz
server: add git server implementation (#190)
* server: add generic server implementation (transport-independent), both for git-upload-pack and git-receive-pack. * server: move internal functions to internal/common. * cli: add git-receive-pack and git-upload-pack implementations. * format/packfile: add UpdateObjectStorage function, extracted from Remote. * transport: implement tranport RPC-like, only with git-upload-pack and git-receive-pack methods. Client renamed to Transport. * storer: add storer.Storer interface. * protocol/packp: add UploadPackResponse constructor with packfile. * protocol/packp: fix UploadPackResponse encoding, add tests. * protocol/packp/capability: implement All.
Diffstat (limited to 'plumbing/transport/file/server_test.go')
-rw-r--r--plumbing/transport/file/server_test.go105
1 files changed, 105 insertions, 0 deletions
diff --git a/plumbing/transport/file/server_test.go b/plumbing/transport/file/server_test.go
new file mode 100644
index 0000000..ff462e2
--- /dev/null
+++ b/plumbing/transport/file/server_test.go
@@ -0,0 +1,105 @@
+package file
+
+import (
+ "fmt"
+ "io"
+ "io/ioutil"
+ "os"
+ "os/exec"
+
+ "gopkg.in/src-d/go-git.v4/fixtures"
+
+ . "gopkg.in/check.v1"
+)
+
+type ServerSuite struct {
+ CommonSuite
+ RemoteName string
+ SrcPath string
+ DstPath string
+ DstURL string
+}
+
+var _ = Suite(&ServerSuite{})
+
+func (s *ServerSuite) SetUpSuite(c *C) {
+ s.CommonSuite.SetUpSuite(c)
+
+ s.RemoteName = "test"
+
+ fixture := fixtures.Basic().One()
+ s.SrcPath = fixture.DotGit().Base()
+
+ fixture = fixtures.ByTag("empty").One()
+ s.DstPath = fixture.DotGit().Base()
+ s.DstURL = fmt.Sprintf("file://%s", s.DstPath)
+
+ cmd := exec.Command("git", "remote", "add", s.RemoteName, s.DstURL)
+ cmd.Dir = s.SrcPath
+ c.Assert(cmd.Run(), IsNil)
+}
+
+func (s *ServerSuite) TestPush(c *C) {
+ // git <2.0 cannot push to an empty repository without a refspec.
+ cmd := exec.Command("git", "push",
+ "--receive-pack", s.ReceivePackBin,
+ s.RemoteName, "refs/heads/*:refs/heads/*",
+ )
+ cmd.Dir = s.SrcPath
+ cmd.Env = os.Environ()
+ cmd.Env = append(cmd.Env, "GIT_TRACE=true", "GIT_TRACE_PACKET=true")
+ stdout, stderr, err := execAndGetOutput(c, cmd)
+ c.Assert(err, IsNil, Commentf("STDOUT:\n%s\nSTDERR:\n%s\n", stdout, stderr))
+}
+
+func (s *ServerSuite) TestClone(c *C) {
+ pathToClone := c.MkDir()
+
+ cmd := exec.Command("git", "clone",
+ "--upload-pack", s.UploadPackBin,
+ s.SrcPath, pathToClone,
+ )
+ cmd.Env = os.Environ()
+ cmd.Env = append(cmd.Env, "GIT_TRACE=true", "GIT_TRACE_PACKET=true")
+ stdout, stderr, err := execAndGetOutput(c, cmd)
+ c.Assert(err, IsNil, Commentf("STDOUT:\n%s\nSTDERR:\n%s\n", stdout, stderr))
+}
+
+func execAndGetOutput(c *C, cmd *exec.Cmd) (stdout, stderr string, err error) {
+ sout, err := cmd.StdoutPipe()
+ c.Assert(err, IsNil)
+ serr, err := cmd.StderrPipe()
+ c.Assert(err, IsNil)
+
+ outChan, outErr := readAllAsync(sout)
+ errChan, errErr := readAllAsync(serr)
+
+ c.Assert(cmd.Start(), IsNil)
+
+ if err = cmd.Wait(); err != nil {
+ return <-outChan, <-errChan, err
+ }
+
+ if err := <-outErr; err != nil {
+ return <-outChan, <-errChan, err
+ }
+
+ return <-outChan, <-errChan, <-errErr
+}
+
+func readAllAsync(r io.Reader) (out chan string, err chan error) {
+ out = make(chan string, 1)
+ err = make(chan error, 1)
+ go func() {
+ b, e := ioutil.ReadAll(r)
+ if e != nil {
+ err <- e
+ } else {
+ err <- nil
+ }
+
+ out <- string(b)
+ }()
+
+ return out, err
+}