aboutsummaryrefslogtreecommitdiffstats
path: root/formats/packp/pktline/scanner_test.go
diff options
context:
space:
mode:
authorAlberto Cortés <alcortesm@gmail.com>2016-10-26 17:56:26 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-10-26 15:56:26 +0000
commit73fa9ef25a8af9c8337a4cf34a67cfe208f1a7c5 (patch)
tree66886d9b47e373b748c1bceafe1885e6f47868dd /formats/packp/pktline/scanner_test.go
parentf3ab3a6c73015b5ae9b2a4756dc646e1211cedb9 (diff)
downloadgo-git-73fa9ef25a8af9c8337a4cf34a67cfe208f1a7c5.tar.gz
Use advrefs in gituploadpackinfo (#92)
* add advrefs encoder and parser * modify advrefs encoder to resemble json encoder * turn advrefs parser into a decoder * clean code * improve documentation * improve documentation * clean code * upgrade to new pktline.Add and add Flush const to easy integration * gometalinter * Use packp/advrefs for GitUploadPackInfo parsing - GitUploadPackInfo now uses packp/advrefs instead of parsing the message by itself. - Capabilities has been moved from clients/common to packp to avoid a circular import. - Cleaning of advrefs_test code. - Add support for prefix encoding and decoding in advrefs. * clean advrefs test code * clean advrefs test code * clean advrefs test code * gometalinter * add pktline encoder * change pktline.EncodeFlush to pktline.Flush * make scanner tests use the encoder instead of Pktlines * check errors on flush and clean constants * ubstitute the PktLines type with a pktline.Encoder * use pktline.Encoder in all go-git * add example of pktline.Encodef() * add package overview * documentation * support symbolic links other than HEAD * simplify decoding of shallows * packp: fix mcuadros comments - all abbreviates removed (by visual inspection, some may remain) - all empty maps are initialized using make - simplify readRef with a switch - make decodeShallow malformed error more verbose - add pktline.Encoder.encodeLine - remove infamous panic in checkPayloadLength by refactoring out the whole function
Diffstat (limited to 'formats/packp/pktline/scanner_test.go')
-rw-r--r--formats/packp/pktline/scanner_test.go46
1 files changed, 30 insertions, 16 deletions
diff --git a/formats/packp/pktline/scanner_test.go b/formats/packp/pktline/scanner_test.go
index de0f8df..b5a3c7d 100644
--- a/formats/packp/pktline/scanner_test.go
+++ b/formats/packp/pktline/scanner_test.go
@@ -1,6 +1,7 @@
package pktline_test
import (
+ "bytes"
"fmt"
"io"
"strings"
@@ -41,11 +42,14 @@ func (s *SuiteScanner) TestEmptyReader(c *C) {
}
func (s *SuiteScanner) TestFlush(c *C) {
- p := pktline.New()
- p.AddFlush()
- sc := pktline.NewScanner(p)
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+ err := e.Flush()
+ c.Assert(err, IsNil)
+ sc := pktline.NewScanner(&buf)
c.Assert(sc.Scan(), Equals, true)
+
payload := sc.Bytes()
c.Assert(len(payload), Equals, 0)
}
@@ -70,14 +74,16 @@ func (s *SuiteScanner) TestScanAndPayload(c *C) {
strings.Repeat("a", pktline.MaxPayloadSize),
strings.Repeat("a", pktline.MaxPayloadSize-1) + "\n",
} {
- p := pktline.New()
- err := p.AddString(test)
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+ err := e.EncodeString(test)
c.Assert(err, IsNil,
Commentf("input len=%x, contents=%.10q\n", len(test), test))
- sc := pktline.NewScanner(p)
+ sc := pktline.NewScanner(&buf)
c.Assert(sc.Scan(), Equals, true,
Commentf("test = %.20q...", test))
+
obtained := sc.Bytes()
c.Assert(obtained, DeepEquals, []byte(test),
Commentf("in = %.20q out = %.20q", test, string(obtained)))
@@ -107,16 +113,19 @@ func (s *SuiteScanner) TestSkip(c *C) {
expected: []byte("third"),
},
} {
- p := pktline.New()
- err := p.AddString(test.input...)
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+ err := e.EncodeString(test.input...)
c.Assert(err, IsNil)
- sc := pktline.NewScanner(p)
+
+ sc := pktline.NewScanner(&buf)
for i := 0; i < test.n; i++ {
c.Assert(sc.Scan(), Equals, true,
Commentf("scan error = %s", sc.Err()))
}
c.Assert(sc.Scan(), Equals, true,
Commentf("scan error = %s", sc.Err()))
+
obtained := sc.Bytes()
c.Assert(obtained, DeepEquals, test.expected,
Commentf("\nin = %.20q\nout = %.20q\nexp = %.20q",
@@ -125,10 +134,12 @@ func (s *SuiteScanner) TestSkip(c *C) {
}
func (s *SuiteScanner) TestEOF(c *C) {
- p := pktline.New()
- err := p.AddString("first", "second")
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+ err := e.EncodeString("first", "second")
c.Assert(err, IsNil)
- sc := pktline.NewScanner(p)
+
+ sc := pktline.NewScanner(&buf)
for sc.Scan() {
}
c.Assert(sc.Err(), IsNil)
@@ -164,19 +175,22 @@ func (s *SuiteScanner) TestReadSomeSections(c *C) {
// 0000
// and so on
func sectionsExample(c *C, nSections, nLines int) io.Reader {
- p := pktline.New()
+ var buf bytes.Buffer
+ e := pktline.NewEncoder(&buf)
+
for section := 0; section < nSections; section++ {
ss := []string{}
for line := 0; line < nLines; line++ {
line := fmt.Sprintf(" %d.%d\n", section, line)
ss = append(ss, line)
}
- err := p.AddString(ss...)
+ err := e.EncodeString(ss...)
+ c.Assert(err, IsNil)
+ err = e.Flush()
c.Assert(err, IsNil)
- p.AddFlush()
}
- return p
+ return &buf
}
func ExampleScanner() {