-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathremote_v2_test.go
More file actions
87 lines (78 loc) · 2.4 KB
/
Copy pathremote_v2_test.go
File metadata and controls
87 lines (78 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package git
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/go-git/go-git/v6/config"
"github.com/go-git/go-git/v6/plumbing"
"github.com/go-git/go-git/v6/plumbing/protocol"
"github.com/go-git/go-git/v6/storage/memory"
)
func (s *RemoteSuite) TestTransportProtocolDefault() {
r := NewRemote(nil, &config.RemoteConfig{Name: "foo", URLs: []string{"https://example.com/foo.git"}})
s.Equal(config.DefaultProtocolVersion, r.transportProtocol())
}
func (s *RemoteSuite) TestTransportProtocolFromConfig() {
st := memory.NewStorage()
cfg, err := st.Config()
s.Require().NoError(err)
cfg.Protocol.Version = protocol.V2
s.Require().NoError(st.SetConfig(cfg))
r := NewRemote(st, &config.RemoteConfig{Name: "foo", URLs: []string{"https://example.com/foo.git"}})
s.Equal(protocol.V2, r.transportProtocol())
}
func TestFetchRefPrefixes(t *testing.T) {
t.Parallel()
tests := []struct {
name string
specs []config.RefSpec
tags plumbing.TagMode
contains []string
wantNil bool
}{
{
name: "short-name source expands to full-name candidates",
specs: []config.RefSpec{"master:foo"},
tags: plumbing.NoTags,
// A v2 server prefix-matches the full refname, so "master" alone
// never matches refs/heads/master; the expansion must cover it.
contains: []string{"master", "refs/heads/master", "refs/tags/master", "HEAD"},
},
{
name: "qualified source is preserved",
specs: []config.RefSpec{"refs/heads/main:refs/heads/main"},
tags: plumbing.NoTags,
contains: []string{"refs/heads/main", "HEAD"},
},
{
name: "wildcard source uses the literal prefix",
specs: []config.RefSpec{"refs/heads/*:refs/remotes/origin/*"},
tags: plumbing.NoTags,
contains: []string{"refs/heads/", "HEAD"},
},
{
name: "leading wildcard requests the full advertisement",
specs: []config.RefSpec{"*:refs/remotes/origin/*"},
tags: plumbing.NoTags,
wantNil: true,
},
{
name: "tag following advertises refs/tags/",
specs: []config.RefSpec{"master:foo"},
tags: plumbing.TagFollowing,
contains: []string{"refs/heads/master", "refs/tags/", "HEAD"},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
got := fetchRefPrefixes(tc.specs, tc.tags)
if tc.wantNil {
assert.Nil(t, got)
return
}
for _, want := range tc.contains {
assert.Contains(t, got, want)
}
})
}
}