1- package packp_test
1+ package packp
22
33import (
44 "bytes"
55 "fmt"
66 "io"
77 "strings"
8- "testing"
98
109 "gopkg.in/src-d/go-git.v4/plumbing"
1110 "gopkg.in/src-d/go-git.v4/plumbing/format/pktline"
12- "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
1311 "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
1412
1513 . "gopkg.in/check.v1"
1614)
1715
18- func Test ( t * testing. T ) { TestingT ( t ) }
16+ type AdvRefSuite struct { }
1917
20- type SuiteDecodeEncode struct {}
18+ var _ = Suite ( & AdvRefSuite {})
2119
22- var _ = Suite (& SuiteDecodeEncode {})
20+ func (s * AdvRefSuite ) TestAddReferenceSymbolic (c * C ) {
21+ ref := plumbing .NewSymbolicReference ("foo" , "bar" )
2322
24- func (s * SuiteDecodeEncode ) test (c * C , in []string , exp []string ) {
23+ a := NewAdvRefs ()
24+ err := a .AddReference (ref )
25+ c .Assert (err , IsNil )
26+
27+ values := a .Capabilities .Get (capability .SymRef )
28+ c .Assert (values , HasLen , 1 )
29+ c .Assert (values [0 ], Equals , "foo:bar" )
30+ }
31+
32+ func (s * AdvRefSuite ) TestAddReferenceHash (c * C ) {
33+ ref := plumbing .NewHashReference ("foo" , plumbing .NewHash ("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c" ))
34+
35+ a := NewAdvRefs ()
36+ err := a .AddReference (ref )
37+ c .Assert (err , IsNil )
38+
39+ c .Assert (a .References , HasLen , 1 )
40+ c .Assert (a .References ["foo" ].String (), Equals , "5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c" )
41+ }
42+
43+ func (s * AdvRefSuite ) TestAllReferences (c * C ) {
44+ hash := plumbing .NewHash ("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c" )
45+
46+ a := NewAdvRefs ()
47+ err := a .AddReference (plumbing .NewSymbolicReference ("foo" , "bar" ))
48+ c .Assert (err , IsNil )
49+ err = a .AddReference (plumbing .NewHashReference ("bar" , hash ))
50+ c .Assert (err , IsNil )
51+
52+ refs , err := a .AllReferences ()
53+ c .Assert (err , IsNil )
54+
55+ iter , err := refs .IterReferences ()
56+ c .Assert (err , IsNil )
57+
58+ var count int
59+ iter .ForEach (func (ref * plumbing.Reference ) error {
60+ count ++
61+ switch ref .Name () {
62+ case "bar" :
63+ c .Assert (ref .Hash (), Equals , hash )
64+ case "foo" :
65+ c .Assert (ref .Target ().String (), Equals , "bar" )
66+ }
67+ return nil
68+ })
69+
70+ c .Assert (count , Equals , 2 )
71+ }
72+
73+ func (s * AdvRefSuite ) TestAllReferencesBadSymref (c * C ) {
74+ a := NewAdvRefs ()
75+ err := a .Capabilities .Set (capability .SymRef , "foo" )
76+ c .Assert (err , IsNil )
77+
78+ _ , err = a .AllReferences ()
79+ c .Assert (err , NotNil )
80+ }
81+
82+ type AdvRefsDecodeEncodeSuite struct {}
83+
84+ var _ = Suite (& AdvRefsDecodeEncodeSuite {})
85+
86+ func (s * AdvRefsDecodeEncodeSuite ) test (c * C , in []string , exp []string ) {
2587 var err error
2688 var input io.Reader
2789 {
@@ -44,7 +106,7 @@ func (s *SuiteDecodeEncode) test(c *C, in []string, exp []string) {
44106
45107 var obtained []byte
46108 {
47- ar := packp . NewAdvRefs ()
109+ ar := NewAdvRefs ()
48110 c .Assert (ar .Decode (input ), IsNil )
49111
50112 var buf bytes.Buffer
@@ -56,7 +118,7 @@ func (s *SuiteDecodeEncode) test(c *C, in []string, exp []string) {
56118 c .Assert (string (obtained ), DeepEquals , string (expected ))
57119}
58120
59- func (s * SuiteDecodeEncode ) TestNoHead (c * C ) {
121+ func (s * AdvRefsDecodeEncodeSuite ) TestNoHead (c * C ) {
60122 input := []string {
61123 "0000000000000000000000000000000000000000 capabilities^{}\x00 " ,
62124 pktline .FlushString ,
@@ -70,7 +132,7 @@ func (s *SuiteDecodeEncode) TestNoHead(c *C) {
70132 s .test (c , input , expected )
71133}
72134
73- func (s * SuiteDecodeEncode ) TestNoHeadSmart (c * C ) {
135+ func (s * AdvRefsDecodeEncodeSuite ) TestNoHeadSmart (c * C ) {
74136 input := []string {
75137 "# service=git-upload-pack\n " ,
76138 "0000000000000000000000000000000000000000 capabilities^{}\x00 " ,
@@ -86,7 +148,7 @@ func (s *SuiteDecodeEncode) TestNoHeadSmart(c *C) {
86148 s .test (c , input , expected )
87149}
88150
89- func (s * SuiteDecodeEncode ) TestNoHeadSmartBug (c * C ) {
151+ func (s * AdvRefsDecodeEncodeSuite ) TestNoHeadSmartBug (c * C ) {
90152 input := []string {
91153 "# service=git-upload-pack\n " ,
92154 pktline .FlushString ,
@@ -104,7 +166,7 @@ func (s *SuiteDecodeEncode) TestNoHeadSmartBug(c *C) {
104166 s .test (c , input , expected )
105167}
106168
107- func (s * SuiteDecodeEncode ) TestRefs (c * C ) {
169+ func (s * AdvRefsDecodeEncodeSuite ) TestRefs (c * C ) {
108170 input := []string {
109171 "6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEAD\x00 symref=HEAD:/refs/heads/master ofs-delta multi_ack" ,
110172 "a6930aaee06755d1bdcfd943fbf614e4d92bb0c7 refs/heads/master" ,
@@ -124,7 +186,7 @@ func (s *SuiteDecodeEncode) TestRefs(c *C) {
124186 s .test (c , input , expected )
125187}
126188
127- func (s * SuiteDecodeEncode ) TestPeeled (c * C ) {
189+ func (s * AdvRefsDecodeEncodeSuite ) TestPeeled (c * C ) {
128190 input := []string {
129191 "6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEAD\x00 symref=HEAD:/refs/heads/master ofs-delta multi_ack" ,
130192 "7777777777777777777777777777777777777777 refs/tags/v2.6.12-tree\n " ,
@@ -148,7 +210,7 @@ func (s *SuiteDecodeEncode) TestPeeled(c *C) {
148210 s .test (c , input , expected )
149211}
150212
151- func (s * SuiteDecodeEncode ) TestAll (c * C ) {
213+ func (s * AdvRefsDecodeEncodeSuite ) TestAll (c * C ) {
152214 input := []string {
153215 "6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEAD\x00 symref=HEAD:/refs/heads/master ofs-delta multi_ack\n " ,
154216 "a6930aaee06755d1bdcfd943fbf614e4d92bb0c7 refs/heads/master\n " ,
@@ -176,7 +238,7 @@ func (s *SuiteDecodeEncode) TestAll(c *C) {
176238 s .test (c , input , expected )
177239}
178240
179- func (s * SuiteDecodeEncode ) TestAllSmart (c * C ) {
241+ func (s * AdvRefsDecodeEncodeSuite ) TestAllSmart (c * C ) {
180242 input := []string {
181243 "# service=git-upload-pack\n " ,
182244 pktline .FlushString ,
@@ -208,7 +270,7 @@ func (s *SuiteDecodeEncode) TestAllSmart(c *C) {
208270 s .test (c , input , expected )
209271}
210272
211- func (s * SuiteDecodeEncode ) TestAllSmartBug (c * C ) {
273+ func (s * AdvRefsDecodeEncodeSuite ) TestAllSmartBug (c * C ) {
212274 input := []string {
213275 "# service=git-upload-pack\n " ,
214276 pktline .FlushString ,
@@ -254,7 +316,7 @@ func ExampleDecoder_Decode() {
254316 input := strings .NewReader (raw )
255317
256318 // Decode the input into a newly allocated AdvRefs value.
257- ar := packp . NewAdvRefs ()
319+ ar := NewAdvRefs ()
258320 _ = ar .Decode (input ) // error check ignored for brevity
259321
260322 // Do something interesting with the AdvRefs, e.g. print its contents.
@@ -270,7 +332,7 @@ func ExampleDecoder_Decode() {
270332
271333func ExampleEncoder_Encode () {
272334 // Create an AdvRefs with the contents you want...
273- ar := packp . NewAdvRefs ()
335+ ar := NewAdvRefs ()
274336
275337 // ...add a hash for the HEAD...
276338 head := plumbing .NewHash ("1111111111111111111111111111111111111111" )
0 commit comments