forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_test.go
More file actions
124 lines (94 loc) · 2.66 KB
/
options_test.go
File metadata and controls
124 lines (94 loc) · 2.66 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
package git
import (
"os"
"testing"
"github.com/go-git/go-billy/v6/util"
"github.com/go-git/go-git/v6/config"
"github.com/go-git/go-git/v6/plumbing"
"github.com/go-git/go-git/v6/plumbing/object"
"github.com/stretchr/testify/suite"
)
type OptionsSuite struct {
BaseSuite
}
func TestOptionsSuite(t *testing.T) {
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"
clean := s.writeGlobalConfig(cfg)
defer clean()
o := CommitOptions{}
err := o.Validate(s.Repository)
s.NoError(err)
s.Equal("foo", o.Author.Name)
s.Equal("foo", o.Committer.Name)
}
func (s *OptionsSuite) TestCommitOptionsLoadGlobalCommitter() {
cfg := config.NewConfig()
cfg.User.Name = "foo"
cfg.Committer.Name = "bar"
clean := s.writeGlobalConfig(cfg)
defer clean()
o := CommitOptions{}
err := o.Validate(s.Repository)
s.NoError(err)
s.Equal("foo", o.Author.Name)
s.Equal("bar", o.Committer.Name)
}
func (s *OptionsSuite) TestCreateTagOptionsLoadGlobal() {
cfg := config.NewConfig()
cfg.User.Name = "foo"
clean := s.writeGlobalConfig(cfg)
defer clean()
o := CreateTagOptions{
Message: "foo",
}
err := o.Validate(s.Repository, plumbing.ZeroHash)
s.NoError(err)
s.Equal("foo", o.Tagger.Name)
}
func (s *OptionsSuite) writeGlobalConfig(cfg *config.Config) func() {
fs := s.TemporalFilesystem()
tmp, err := util.TempDir(fs, "", "test-options")
s.NoError(err)
err = fs.MkdirAll(fs.Join(tmp, "git"), 0777)
s.NoError(err)
os.Setenv("XDG_CONFIG_HOME", fs.Join(fs.Root(), tmp))
content, err := cfg.Marshal()
s.NoError(err)
cfgFile := fs.Join(tmp, "git/config")
err = util.WriteFile(fs, cfgFile, content, 0777)
s.NoError(err)
return func() {
os.Setenv("XDG_CONFIG_HOME", "")
}
}