diff options
author | Alberto Cortés <alcortesm@gmail.com> | 2016-10-26 17:56:26 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-10-26 15:56:26 +0000 |
commit | 73fa9ef25a8af9c8337a4cf34a67cfe208f1a7c5 (patch) | |
tree | 66886d9b47e373b748c1bceafe1885e6f47868dd /formats/packp/pktline/pktlines_test.go | |
parent | f3ab3a6c73015b5ae9b2a4756dc646e1211cedb9 (diff) | |
download | go-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/pktlines_test.go')
-rw-r--r-- | formats/packp/pktline/pktlines_test.go | 231 |
1 files changed, 0 insertions, 231 deletions
diff --git a/formats/packp/pktline/pktlines_test.go b/formats/packp/pktline/pktlines_test.go deleted file mode 100644 index e0ba16b..0000000 --- a/formats/packp/pktline/pktlines_test.go +++ /dev/null @@ -1,231 +0,0 @@ -package pktline_test - -import ( - "io" - "io/ioutil" - "os" - "strings" - "testing" - - "gopkg.in/src-d/go-git.v4/formats/packp/pktline" - - . "gopkg.in/check.v1" -) - -func Test(t *testing.T) { TestingT(t) } - -type SuitePktLine struct { -} - -var _ = Suite(&SuitePktLine{}) - -func (s *SuitePktLine) TestNewIsEmpty(c *C) { - p := pktline.New() - - b, err := ioutil.ReadAll(p) - c.Assert(err, IsNil) - c.Assert(b, DeepEquals, []byte{}) -} - -func (s *SuitePktLine) TestAddFlush(c *C) { - p := pktline.New() - p.AddFlush() - - b, err := ioutil.ReadAll(p) - c.Assert(err, IsNil) - c.Assert(string(b), DeepEquals, "0000") -} - -func (s *SuitePktLine) TestAdd(c *C) { - for i, test := range [...]struct { - input [][]byte - expected []byte - }{ - { - input: [][]byte{ - []byte("hello\n"), - }, - expected: []byte("000ahello\n"), - }, { - input: [][]byte{ - []byte("hello\n"), - []byte("world!\n"), - []byte("foo"), - }, - expected: []byte("000ahello\n000bworld!\n0007foo"), - }, { - input: [][]byte{ - []byte(strings.Repeat("a", pktline.MaxPayloadSize)), - }, - expected: []byte( - "fff0" + strings.Repeat("a", pktline.MaxPayloadSize)), - }, { - input: [][]byte{ - []byte(strings.Repeat("a", pktline.MaxPayloadSize)), - []byte(strings.Repeat("b", pktline.MaxPayloadSize)), - }, - expected: []byte( - "fff0" + strings.Repeat("a", pktline.MaxPayloadSize) + - "fff0" + strings.Repeat("b", pktline.MaxPayloadSize)), - }, - } { - p := pktline.New() - err := p.Add(test.input...) - c.Assert(err, IsNil, Commentf("input %d = %v", i, test.input)) - - obtained, err := ioutil.ReadAll(p) - c.Assert(err, IsNil, Commentf("input %d = %v", i, test.input)) - - c.Assert(obtained, DeepEquals, test.expected, - Commentf("input %d = %v", i, test.input)) - } -} - -func (s *SuitePktLine) TestAddErrEmptyPayload(c *C) { - for _, input := range [...][][]byte{ - [][]byte{ - []byte{}, - }, - [][]byte{ - []byte(nil), - }, - [][]byte{ - []byte("hello world!"), - []byte{}, - }, - [][]byte{ - []byte{}, - []byte("hello world!"), - }, - } { - p := pktline.New() - err := p.Add(input...) - c.Assert(err, Equals, pktline.ErrEmptyPayload) - } -} - -func (s *SuitePktLine) TestAddErrPayloadTooLong(c *C) { - for _, input := range [...][][]byte{ - [][]byte{ - []byte(strings.Repeat("a", pktline.MaxPayloadSize+1)), - }, - [][]byte{ - []byte("hello world!"), - []byte(strings.Repeat("a", pktline.MaxPayloadSize+1)), - }, - [][]byte{ - []byte("hello world!"), - []byte(strings.Repeat("a", pktline.MaxPayloadSize+1)), - []byte("foo"), - }, - } { - p := pktline.New() - err := p.Add(input...) - c.Assert(err, Equals, pktline.ErrPayloadTooLong, - Commentf("%v\n", input)) - } -} - -func (s *SuitePktLine) TestAddString(c *C) { - for i, test := range [...]struct { - input []string - expected []byte - }{ - { - input: []string{ - "hello\n", - }, - expected: []byte("000ahello\n"), - }, { - input: []string{ - "hello\n", - "world!\n", - "foo", - }, - expected: []byte("000ahello\n000bworld!\n0007foo"), - }, { - input: []string{ - strings.Repeat("a", pktline.MaxPayloadSize), - }, - expected: []byte( - "fff0" + strings.Repeat("a", pktline.MaxPayloadSize)), - }, { - input: []string{ - strings.Repeat("a", pktline.MaxPayloadSize), - strings.Repeat("b", pktline.MaxPayloadSize), - }, - expected: []byte( - "fff0" + strings.Repeat("a", pktline.MaxPayloadSize) + - "fff0" + strings.Repeat("b", pktline.MaxPayloadSize)), - }, - } { - p := pktline.New() - err := p.AddString(test.input...) - c.Assert(err, IsNil, Commentf("input %d = %v", i, test.input)) - - obtained, err := ioutil.ReadAll(p) - c.Assert(err, IsNil, Commentf("input %d = %v", i, test.input)) - - c.Assert(obtained, DeepEquals, test.expected, - Commentf("input %d = %v", i, test.input)) - } -} - -func (s *SuitePktLine) TestAddStringErrEmptyPayload(c *C) { - for _, input := range [...][]string{ - []string{""}, - []string{"hello world!", ""}, - []string{"", "hello world!"}, - } { - p := pktline.New() - err := p.AddString(input...) - c.Assert(err, Equals, pktline.ErrEmptyPayload) - } -} - -func (s *SuitePktLine) TestAddStringErrPayloadTooLong(c *C) { - for _, input := range [...][]string{ - []string{ - strings.Repeat("a", pktline.MaxPayloadSize+1), - }, - []string{ - "hello world!", - strings.Repeat("a", pktline.MaxPayloadSize+1), - }, - []string{ - "hello world!", - strings.Repeat("a", pktline.MaxPayloadSize+1), - "foo", - }, - } { - p := pktline.New() - err := p.AddString(input...) - c.Assert(err, Equals, pktline.ErrPayloadTooLong, - Commentf("%v\n", input)) - } -} - -func ExamplePktLines() { - // Create an empty collection of pktlines. - p := pktline.New() - - // Add two strings as payloads ("foo\n" and "bar\n"), they will - // end up as two consecutive pktlines. - p.AddString("foo\n", "bar\n") // error checks removed for brevity - - // You can also add byte slices as payloads... - p.Add([]byte("hello\n"), []byte("world!\n")) - - // Add a flush-pkt. - p.AddFlush() - - // PktLines are Readers, so you can directly read the full sequence. - io.Copy(os.Stdout, p) - - // Output: - // 0008foo - // 0008bar - // 000ahello - // 000bworld! - // 0000 -} |