2016-05-31 16:38:47 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/github/git-lfs/config"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-08-03 23:42:21 +00:00
|
|
|
testcfg = config.NewFrom(config.Values{
|
|
|
|
Git: map[string]string{
|
|
|
|
"lfs.fetchinclude": "/default/include",
|
|
|
|
"lfs.fetchexclude": "/default/exclude",
|
|
|
|
},
|
2016-05-31 16:38:47 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDetermineIncludeExcludePathsReturnsCleanedPaths(t *testing.T) {
|
2016-08-01 22:47:41 +00:00
|
|
|
inc := "/some/include"
|
|
|
|
exc := "/some/exclude"
|
|
|
|
i, e := determineIncludeExcludePaths(testcfg, &inc, &exc)
|
2016-05-31 16:38:47 +00:00
|
|
|
|
|
|
|
assert.Equal(t, []string{"/some/include"}, i)
|
|
|
|
assert.Equal(t, []string{"/some/exclude"}, e)
|
|
|
|
}
|
|
|
|
|
2016-08-01 22:47:41 +00:00
|
|
|
func TestDetermineIncludeExcludePathsReturnsEmptyPaths(t *testing.T) {
|
|
|
|
inc := ""
|
|
|
|
exc := ""
|
|
|
|
i, e := determineIncludeExcludePaths(testcfg, &inc, &exc)
|
|
|
|
|
|
|
|
assert.Empty(t, i)
|
|
|
|
assert.Empty(t, e)
|
|
|
|
}
|
|
|
|
|
2016-05-31 16:38:47 +00:00
|
|
|
func TestDetermineIncludeExcludePathsReturnsDefaultsWhenAbsent(t *testing.T) {
|
2016-08-01 22:47:41 +00:00
|
|
|
i, e := determineIncludeExcludePaths(testcfg, nil, nil)
|
2016-05-31 16:38:47 +00:00
|
|
|
|
|
|
|
assert.Equal(t, []string{"/default/include"}, i)
|
|
|
|
assert.Equal(t, []string{"/default/exclude"}, e)
|
|
|
|
}
|
2016-07-21 16:37:56 +00:00
|
|
|
|
|
|
|
func TestCommandEnabledFromEnvironmentVariables(t *testing.T) {
|
2016-07-21 23:38:44 +00:00
|
|
|
cfg := config.New()
|
2016-07-21 16:37:56 +00:00
|
|
|
err := cfg.Setenv("GITLFSLOCKSENABLED", "1")
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.True(t, isCommandEnabled(cfg, "locks"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandEnabledDisabledByDefault(t *testing.T) {
|
2016-07-21 23:38:44 +00:00
|
|
|
cfg := config.New()
|
2016-07-21 16:37:56 +00:00
|
|
|
|
|
|
|
// Since config.Configuration.Setenv makes a call to os.Setenv, we have
|
|
|
|
// to make sure that the LFSLOCKSENABLED enviornment variable is not
|
|
|
|
// present in the configuration object during the lifecycle of this
|
|
|
|
// test.
|
|
|
|
//
|
|
|
|
// This behavior can cause race conditions with the above test when
|
|
|
|
// running in parallel, so this should be investigated further in the
|
|
|
|
// future.
|
|
|
|
err := cfg.Setenv("GITLFSLOCKSENABLED", "")
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.False(t, isCommandEnabled(cfg, "locks"))
|
|
|
|
}
|