7 "github.com/stretchr/testify/assert"
10 func TestBasicTransfersOnlySetValue(t *testing.T) {
11 cfg := NewFrom(Values{
12 Git: map[string][]string{
13 "lfs.basictransfersonly": []string{"true"},
17 b := cfg.BasicTransfersOnly()
18 assert.Equal(t, true, b)
21 func TestBasicTransfersOnlyDefault(t *testing.T) {
22 cfg := NewFrom(Values{})
24 b := cfg.BasicTransfersOnly()
25 assert.Equal(t, false, b)
28 func TestBasicTransfersOnlyInvalidValue(t *testing.T) {
29 cfg := NewFrom(Values{
30 Git: map[string][]string{
31 "lfs.basictransfersonly": []string{"wat"},
35 b := cfg.BasicTransfersOnly()
36 assert.Equal(t, false, b)
39 func TestTusTransfersAllowedSetValue(t *testing.T) {
40 cfg := NewFrom(Values{
41 Git: map[string][]string{
42 "lfs.tustransfers": []string{"true"},
46 b := cfg.TusTransfersAllowed()
47 assert.Equal(t, true, b)
50 func TestTusTransfersAllowedDefault(t *testing.T) {
51 cfg := NewFrom(Values{})
53 b := cfg.TusTransfersAllowed()
54 assert.Equal(t, false, b)
57 func TestTusTransfersAllowedInvalidValue(t *testing.T) {
58 cfg := NewFrom(Values{
59 Git: map[string][]string{
60 "lfs.tustransfers": []string{"wat"},
64 b := cfg.TusTransfersAllowed()
65 assert.Equal(t, false, b)
68 func TestLoadValidExtension(t *testing.T) {
69 cfg := NewFrom(Values{
70 Git: map[string][]string{},
73 cfg.extensions = map[string]Extension{
82 ext := cfg.Extensions()["foo"]
84 assert.Equal(t, "foo", ext.Name)
85 assert.Equal(t, "foo-clean %f", ext.Clean)
86 assert.Equal(t, "foo-smudge %f", ext.Smudge)
87 assert.Equal(t, 2, ext.Priority)
90 func TestLoadInvalidExtension(t *testing.T) {
91 cfg := NewFrom(Values{})
92 ext := cfg.Extensions()["foo"]
94 assert.Equal(t, "", ext.Name)
95 assert.Equal(t, "", ext.Clean)
96 assert.Equal(t, "", ext.Smudge)
97 assert.Equal(t, 0, ext.Priority)
100 func TestFetchPruneConfigDefault(t *testing.T) {
101 cfg := NewFrom(Values{})
102 fp := cfg.FetchPruneConfig()
104 assert.Equal(t, 7, fp.FetchRecentRefsDays)
105 assert.Equal(t, 0, fp.FetchRecentCommitsDays)
106 assert.Equal(t, 3, fp.PruneOffsetDays)
107 assert.True(t, fp.FetchRecentRefsIncludeRemotes)
108 assert.Equal(t, 3, fp.PruneOffsetDays)
109 assert.Equal(t, "origin", fp.PruneRemoteName)
110 assert.False(t, fp.PruneVerifyRemoteAlways)
113 func TestFetchPruneConfigCustom(t *testing.T) {
114 cfg := NewFrom(Values{
115 Git: map[string][]string{
116 "lfs.fetchrecentrefsdays": []string{"12"},
117 "lfs.fetchrecentremoterefs": []string{"false"},
118 "lfs.fetchrecentcommitsdays": []string{"9"},
119 "lfs.pruneoffsetdays": []string{"30"},
120 "lfs.pruneverifyremotealways": []string{"true"},
121 "lfs.pruneremotetocheck": []string{"upstream"},
124 fp := cfg.FetchPruneConfig()
126 assert.Equal(t, 12, fp.FetchRecentRefsDays)
127 assert.Equal(t, 9, fp.FetchRecentCommitsDays)
128 assert.False(t, fp.FetchRecentRefsIncludeRemotes)
129 assert.Equal(t, 30, fp.PruneOffsetDays)
130 assert.Equal(t, "upstream", fp.PruneRemoteName)
131 assert.True(t, fp.PruneVerifyRemoteAlways)
134 func TestFetchIncludeExcludesAreCleaned(t *testing.T) {
135 cfg := NewFrom(Values{
136 Git: map[string][]string{
137 "lfs.fetchinclude": []string{"/path/to/clean/"},
138 "lfs.fetchexclude": []string{"/other/path/to/clean/"},
142 assert.Equal(t, []string{"/path/to/clean"}, cfg.FetchIncludePaths())
143 assert.Equal(t, []string{"/other/path/to/clean"}, cfg.FetchExcludePaths())
146 func TestUnmarshalMultipleTypes(t *testing.T) {
147 cfg := NewFrom(Values{
148 Git: map[string][]string{
149 "string": []string{"string"},
150 "int": []string{"1"},
151 "bool": []string{"true"},
153 Os: map[string][]string{
154 "string": []string{"string"},
155 "int": []string{"1"},
156 "bool": []string{"true"},
161 GitString string `git:"string"`
162 GitInt int `git:"int"`
163 GitBool bool `git:"bool"`
164 OsString string `os:"string"`
166 OsBool bool `os:"bool"`
169 assert.Nil(t, cfg.Unmarshal(v))
171 assert.Equal(t, "string", v.GitString)
172 assert.Equal(t, 1, v.GitInt)
173 assert.Equal(t, true, v.GitBool)
174 assert.Equal(t, "string", v.OsString)
175 assert.Equal(t, 1, v.OsInt)
176 assert.Equal(t, true, v.OsBool)
179 func TestUnmarshalErrsOnNonPointerType(t *testing.T) {
181 Foo string `git:"foo"`
184 cfg := NewFrom(Values{})
186 err := cfg.Unmarshal(T{})
188 assert.Equal(t, "lfs/config: unable to parse non-pointer type of config.T", err.Error())
191 func TestUnmarshalLeavesNonZeroValuesWhenKeysEmpty(t *testing.T) {
193 String string `git:"string"`
195 Bool bool `git:"bool"`
198 cfg := NewFrom(Values{})
200 err := cfg.Unmarshal(v)
203 assert.Equal(t, "foo", v.String)
204 assert.Equal(t, 1, v.Int)
205 assert.Equal(t, true, v.Bool)
208 func TestUnmarshalOverridesNonZeroValuesWhenValuesPresent(t *testing.T) {
210 String string `git:"string"`
212 Bool bool `git:"bool"`
215 cfg := NewFrom(Values{
216 Git: map[string][]string{
217 "string": []string{"bar"},
218 "int": []string{"2"},
219 "bool": []string{"false"},
223 err := cfg.Unmarshal(v)
226 assert.Equal(t, "bar", v.String)
227 assert.Equal(t, 2, v.Int)
228 assert.Equal(t, false, v.Bool)
231 func TestUnmarshalAllowsBothOsAndGitTags(t *testing.T) {
233 String string `git:"string" os:"STRING"`
236 cfg := NewFrom(Values{
237 Git: map[string][]string{"string": []string{"foo"}},
238 Os: map[string][]string{"STRING": []string{"bar"}},
241 err := cfg.Unmarshal(v)
244 assert.Equal(t, "foo", v.String)
247 func TestUnmarshalYieldsToDefaultIfBothEnvsMissing(t *testing.T) {
249 String string `git:"string" os:"STRING"`
252 cfg := NewFrom(Values{})
254 err := cfg.Unmarshal(v)
257 assert.Equal(t, "foo", v.String)
260 func TestUnmarshalOverridesDefaultIfAnyEnvPresent(t *testing.T) {
262 String string `git:"string" os:"STRING"`
265 cfg := NewFrom(Values{
266 Git: map[string][]string{"string": []string{"bar"}},
267 Os: map[string][]string{"STRING": []string{"baz"}},
270 err := cfg.Unmarshal(v)
273 assert.Equal(t, "bar", v.String)
276 func TestUnmarshalIgnoresUnknownEnvironments(t *testing.T) {
278 String string `unknown:"string"`
281 cfg := NewFrom(Values{})
283 assert.Nil(t, cfg.Unmarshal(v))
286 func TestUnmarshalErrsOnUnsupportedTypes(t *testing.T) {
288 Unsupported time.Duration `git:"duration"`
291 cfg := NewFrom(Values{
292 Git: map[string][]string{"duration": []string{"foo"}},
295 err := cfg.Unmarshal(v)
297 assert.Equal(t, "lfs/config: unsupported target type for field \"Unsupported\": time.Duration", err.Error())