Repository navigation
Expand file tree
/
Copy pathoptions_test.go
More file actions
128 lines (102 loc) · 3.21 KB
/
Copy pathoptions_test.go
File metadata and controls
128 lines (102 loc) · 3.21 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package git
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/suite"
"github.com/go-git/go-git/v6/config"
testconfig "github.com/go-git/go-git/v6/internal/test/config"
"github.com/go-git/go-git/v6/plumbing"
"github.com/go-git/go-git/v6/plumbing/object"
)
type OptionsSuite struct {
BaseSuite
}
func TestOptionsSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(OptionsSuite))
}
func (s *OptionsSuite) TestCommitOptionsParentsFromHEAD() {
o := CommitOptions{Author: &object.Signature{}}
err := o.Validate(s.Repository)
s.NoError(err)
s.Len(o.Parents, 1)
}
func (s *OptionsSuite) TestResetOptionsCommitNotFound() {
o := ResetOptions{Commit: plumbing.NewHash("ab1b15c6f6487b4db16f10d8ec69bb8bf91dcabd")}
err := o.Validate(s.Repository)
s.NotNil(err)
}
func (s *OptionsSuite) TestCommitOptionsCommitter() {
sig := &object.Signature{}
o := CommitOptions{Author: sig}
err := o.Validate(s.Repository)
s.NoError(err)
s.Equal(o.Author, o.Committer)
}
func (s *OptionsSuite) TestCommitOptionsLoadGlobalConfigUser() {
cfg := config.NewConfig()
cfg.User.Name = "foo"
cfg.User.Email = "foo@foo.com"
clean := s.registerGlobalConfig(cfg)
defer clean()
o := CommitOptions{}
err := o.Validate(s.Repository)
s.NoError(err)
s.Equal("foo", o.Author.Name)
s.Equal("foo@foo.com", o.Author.Email)
s.Equal("foo", o.Committer.Name)
s.Equal("foo@foo.com", o.Committer.Email)
}
func (s *OptionsSuite) TestCommitOptionsLoadGlobalCommitter() {
cfg := config.NewConfig()
cfg.User.Name = "foo"
cfg.User.Email = "foo@foo.com"
cfg.Committer.Name = "bar"
cfg.Committer.Email = "bar@bar.com"
clean := s.registerGlobalConfig(cfg)
defer clean()
o := CommitOptions{}
err := o.Validate(s.Repository)
s.NoError(err)
s.Equal("foo", o.Author.Name)
s.Equal("foo@foo.com", o.Author.Email)
s.Equal("bar", o.Committer.Name)
s.Equal("bar@bar.com", o.Committer.Email)
}
func (s *OptionsSuite) TestCreateTagOptionsLoadGlobal() {
cfg := config.NewConfig()
cfg.User.Name = "foo"
cfg.User.Email = "foo@foo.com"
clean := s.registerGlobalConfig(cfg)
defer clean()
o := CreateTagOptions{
Message: "foo",
}
err := o.Validate(s.Repository, plumbing.ZeroHash)
s.NoError(err)
s.Equal("foo", o.Tagger.Name)
s.Equal("foo@foo.com", o.Tagger.Email)
}
// TestCloneOptionsValidate_RelativeDotDot verifies that ..-relative local
// paths in CloneOptions.URL are resolved to absolute paths by Validate, so
// that the billy chroot-based FilesystemLoader never sees a ".." component.
//
// Fixes: https://github.com/go-git/go-git/issues/1723
func (s *OptionsSuite) TestCloneOptionsValidate_RelativeDotDot() {
for _, input := range []string{"../../", "../foo", ".."} {
o := &CloneOptions{URL: input}
err := o.Validate()
s.NoError(err, "input %q", input)
s.True(filepath.IsAbs(o.URL),
"..-relative URL %q must be resolved to absolute after Validate, got %q", input, o.URL)
}
}
// registerGlobalConfig registers a static ConfigSource plugin with the
// given config as the global config. It returns a cleanup function that
// restores the default test ConfigSource.
func (s *OptionsSuite) registerGlobalConfig(cfg *config.Config) func() {
testconfig.Register(*cfg, *config.NewConfig())
return func() {
registerTestConfigLoader()
}
}