2015-03-19 19:30:55 +00:00
|
|
|
package lfs
|
2014-02-01 21:09:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-05-13 19:43:41 +00:00
|
|
|
|
2015-05-25 18:20:50 +00:00
|
|
|
"github.com/github/git-lfs/vendor/_nuts/github.com/technoweenie/assert"
|
2014-02-01 21:09:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEndpointDefaultsToOrigin(t *testing.T) {
|
|
|
|
config := &Configuration{
|
2015-04-15 19:24:44 +00:00
|
|
|
gitConfig: map[string]string{"remote.origin.lfsurl": "abc"},
|
2015-01-12 00:53:10 +00:00
|
|
|
remotes: []string{},
|
2014-02-01 21:09:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "abc", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2014-02-01 21:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEndpointOverridesOrigin(t *testing.T) {
|
|
|
|
config := &Configuration{
|
2015-01-12 00:53:10 +00:00
|
|
|
gitConfig: map[string]string{
|
2015-04-15 19:24:44 +00:00
|
|
|
"lfs.url": "abc",
|
|
|
|
"remote.origin.lfsurl": "def",
|
2014-02-01 21:09:52 +00:00
|
|
|
},
|
2015-01-12 00:53:10 +00:00
|
|
|
remotes: []string{},
|
2014-02-01 21:09:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "abc", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2014-02-01 21:09:52 +00:00
|
|
|
}
|
2014-05-22 23:02:56 +00:00
|
|
|
|
2015-02-02 22:39:03 +00:00
|
|
|
func TestEndpointNoOverrideDefaultRemote(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
2015-04-15 19:24:44 +00:00
|
|
|
"remote.origin.lfsurl": "abc",
|
|
|
|
"remote.other.lfsurl": "def",
|
2015-02-02 22:39:03 +00:00
|
|
|
},
|
|
|
|
remotes: []string{},
|
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "abc", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2015-02-02 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEndpointUseAlternateRemote(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
2015-04-15 19:24:44 +00:00
|
|
|
"remote.origin.lfsurl": "abc",
|
|
|
|
"remote.other.lfsurl": "def",
|
2015-02-02 22:39:03 +00:00
|
|
|
},
|
|
|
|
remotes: []string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.CurrentRemote = "other"
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "def", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2015-02-02 22:39:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:21:08 +00:00
|
|
|
func TestEndpointAddsLfsSuffix(t *testing.T) {
|
2014-05-22 23:02:56 +00:00
|
|
|
config := &Configuration{
|
2015-01-12 00:53:10 +00:00
|
|
|
gitConfig: map[string]string{"remote.origin.url": "https://example.com/foo/bar"},
|
|
|
|
remotes: []string{},
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:21:08 +00:00
|
|
|
func TestBareEndpointAddsLfsSuffix(t *testing.T) {
|
2014-05-22 23:02:56 +00:00
|
|
|
config := &Configuration{
|
2015-01-12 00:53:10 +00:00
|
|
|
gitConfig: map[string]string{"remote.origin.url": "https://example.com/foo/bar.git"},
|
|
|
|
remotes: []string{},
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSSHEndpointOverridden(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
2015-04-15 19:24:44 +00:00
|
|
|
"remote.origin.url": "git@example.com:foo/bar",
|
|
|
|
"remote.origin.lfsurl": "lfs",
|
2015-03-27 22:36:33 +00:00
|
|
|
},
|
|
|
|
remotes: []string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2015-06-22 09:46:40 +00:00
|
|
|
assert.Equal(t, "", endpoint.SshPort)
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:21:08 +00:00
|
|
|
func TestSSHEndpointAddsLfsSuffix(t *testing.T) {
|
2014-05-22 23:02:56 +00:00
|
|
|
config := &Configuration{
|
2015-06-22 09:46:40 +00:00
|
|
|
gitConfig: map[string]string{"remote.origin.url": "ssh://git@example.com/foo/bar"},
|
2015-01-12 00:53:10 +00:00
|
|
|
remotes: []string{},
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "git@example.com", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "foo/bar", endpoint.SshPath)
|
2015-06-22 09:46:40 +00:00
|
|
|
assert.Equal(t, "", endpoint.SshPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSSHCustomPortEndpointAddsLfsSuffix(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{"remote.origin.url": "ssh://git@example.com:9000/foo/bar"},
|
|
|
|
remotes: []string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "git@example.com", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "foo/bar", endpoint.SshPath)
|
|
|
|
assert.Equal(t, "9000", endpoint.SshPort)
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:21:08 +00:00
|
|
|
func TestBareSSHEndpointAddsLfsSuffix(t *testing.T) {
|
2014-05-22 23:02:56 +00:00
|
|
|
config := &Configuration{
|
2015-01-12 00:53:10 +00:00
|
|
|
gitConfig: map[string]string{"remote.origin.url": "git@example.com:foo/bar.git"},
|
|
|
|
remotes: []string{},
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "git@example.com", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "foo/bar.git", endpoint.SshPath)
|
2015-06-22 09:46:40 +00:00
|
|
|
assert.Equal(t, "", endpoint.SshPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSSHEndpointFromGlobalLfsUrl(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{"lfs.url": "git@example.com:foo/bar.git"},
|
|
|
|
remotes: []string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "https://example.com/foo/bar.git", endpoint.Url)
|
|
|
|
assert.Equal(t, "git@example.com", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "foo/bar.git", endpoint.SshPath)
|
|
|
|
assert.Equal(t, "", endpoint.SshPort)
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:21:08 +00:00
|
|
|
func TestHTTPEndpointAddsLfsSuffix(t *testing.T) {
|
2014-05-22 23:02:56 +00:00
|
|
|
config := &Configuration{
|
2015-01-12 00:53:10 +00:00
|
|
|
gitConfig: map[string]string{"remote.origin.url": "http://example.com/foo/bar"},
|
|
|
|
remotes: []string{},
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "http://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2015-06-22 09:46:40 +00:00
|
|
|
assert.Equal(t, "", endpoint.SshPort)
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:21:08 +00:00
|
|
|
func TestBareHTTPEndpointAddsLfsSuffix(t *testing.T) {
|
2014-05-22 23:02:56 +00:00
|
|
|
config := &Configuration{
|
2015-01-12 00:53:10 +00:00
|
|
|
gitConfig: map[string]string{"remote.origin.url": "http://example.com/foo/bar.git"},
|
|
|
|
remotes: []string{},
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:36:33 +00:00
|
|
|
endpoint := config.Endpoint()
|
|
|
|
assert.Equal(t, "http://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
|
|
|
assert.Equal(t, "", endpoint.SshUserAndHost)
|
|
|
|
assert.Equal(t, "", endpoint.SshPath)
|
2015-06-22 09:46:40 +00:00
|
|
|
assert.Equal(t, "", endpoint.SshPort)
|
2014-05-22 23:02:56 +00:00
|
|
|
}
|
2015-02-13 23:25:05 +00:00
|
|
|
|
|
|
|
func TestObjectUrl(t *testing.T) {
|
2015-08-28 21:19:52 +00:00
|
|
|
defer Config.ResetConfig()
|
2015-02-13 23:25:05 +00:00
|
|
|
tests := map[string]string{
|
|
|
|
"http://example.com": "http://example.com/objects/oid",
|
|
|
|
"http://example.com/": "http://example.com/objects/oid",
|
|
|
|
"http://example.com/foo": "http://example.com/foo/objects/oid",
|
|
|
|
"http://example.com/foo/": "http://example.com/foo/objects/oid",
|
|
|
|
}
|
|
|
|
|
|
|
|
for endpoint, expected := range tests {
|
2015-03-19 19:30:55 +00:00
|
|
|
Config.SetConfig("lfs.url", endpoint)
|
2015-03-19 20:39:44 +00:00
|
|
|
u, err := Config.ObjectUrl("oid")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error building URL for %s: %s", endpoint, err)
|
|
|
|
} else {
|
|
|
|
if actual := u.String(); expected != actual {
|
|
|
|
t.Errorf("Expected %s, got %s", expected, u.String())
|
|
|
|
}
|
|
|
|
}
|
2015-02-13 23:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-19 21:16:52 +00:00
|
|
|
|
|
|
|
func TestObjectsUrl(t *testing.T) {
|
2015-08-28 21:19:52 +00:00
|
|
|
defer Config.ResetConfig()
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
tests := map[string]string{
|
|
|
|
"http://example.com": "http://example.com/objects",
|
|
|
|
"http://example.com/": "http://example.com/objects",
|
|
|
|
"http://example.com/foo": "http://example.com/foo/objects",
|
|
|
|
"http://example.com/foo/": "http://example.com/foo/objects",
|
|
|
|
}
|
|
|
|
|
|
|
|
for endpoint, expected := range tests {
|
|
|
|
Config.SetConfig("lfs.url", endpoint)
|
|
|
|
u, err := Config.ObjectUrl("")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error building URL for %s: %s", endpoint, err)
|
|
|
|
} else {
|
|
|
|
if actual := u.String(); expected != actual {
|
|
|
|
t.Errorf("Expected %s, got %s", expected, u.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-26 19:42:37 +00:00
|
|
|
|
|
|
|
func TestConcurrentTransfersSetValue(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
|
|
|
"lfs.concurrenttransfers": "5",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
n := config.ConcurrentTransfers()
|
|
|
|
assert.Equal(t, 5, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConcurrentTransfersDefault(t *testing.T) {
|
|
|
|
config := &Configuration{}
|
|
|
|
|
|
|
|
n := config.ConcurrentTransfers()
|
|
|
|
assert.Equal(t, 3, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConcurrentTransfersZeroValue(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
|
|
|
"lfs.concurrenttransfers": "0",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
n := config.ConcurrentTransfers()
|
|
|
|
assert.Equal(t, 3, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConcurrentTransfersNonNumeric(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
|
|
|
"lfs.concurrenttransfers": "elephant",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
n := config.ConcurrentTransfers()
|
|
|
|
assert.Equal(t, 3, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConcurrentTransfersNegativeValue(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
|
|
|
"lfs.concurrenttransfers": "-5",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
n := config.ConcurrentTransfers()
|
|
|
|
assert.Equal(t, 3, n)
|
|
|
|
}
|
|
|
|
|
2015-09-02 16:43:52 +00:00
|
|
|
func TestBatch(t *testing.T) {
|
|
|
|
tests := map[string]bool{
|
2015-09-02 17:52:38 +00:00
|
|
|
"": true,
|
2015-09-02 16:43:52 +00:00
|
|
|
"true": true,
|
|
|
|
"1": true,
|
2015-09-02 17:52:38 +00:00
|
|
|
"42": false,
|
|
|
|
"-1": false,
|
2015-09-02 16:43:52 +00:00
|
|
|
"0": false,
|
|
|
|
"false": false,
|
|
|
|
"elephant": false,
|
2015-05-26 19:42:37 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 16:43:52 +00:00
|
|
|
for value, expected := range tests {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{"lfs.batch": value},
|
|
|
|
}
|
2015-05-26 19:42:37 +00:00
|
|
|
|
2015-09-02 16:43:52 +00:00
|
|
|
if actual := config.BatchTransfer(); actual != expected {
|
|
|
|
t.Errorf("lfs.batch %q == %v, not %v", value, actual, expected)
|
|
|
|
}
|
2015-05-26 19:42:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 20:31:51 +00:00
|
|
|
func TestBatchAbsentIsTrue(t *testing.T) {
|
2015-05-26 19:42:37 +00:00
|
|
|
config := &Configuration{}
|
|
|
|
|
|
|
|
v := config.BatchTransfer()
|
2015-09-01 20:31:51 +00:00
|
|
|
assert.Equal(t, true, v)
|
2015-05-26 19:42:37 +00:00
|
|
|
}
|
2015-07-10 20:54:06 +00:00
|
|
|
|
|
|
|
func TestLoadValidExtension(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{},
|
|
|
|
extensions: map[string]Extension{
|
|
|
|
"foo": Extension{
|
|
|
|
"foo",
|
|
|
|
"foo-clean %f",
|
|
|
|
"foo-smudge %f",
|
|
|
|
2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
ext := config.Extensions()["foo"]
|
|
|
|
|
|
|
|
assert.Equal(t, "foo", ext.Name)
|
|
|
|
assert.Equal(t, "foo-clean %f", ext.Clean)
|
|
|
|
assert.Equal(t, "foo-smudge %f", ext.Smudge)
|
|
|
|
assert.Equal(t, 2, ext.Priority)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadInvalidExtension(t *testing.T) {
|
|
|
|
config := &Configuration{}
|
|
|
|
|
|
|
|
ext := config.Extensions()["foo"]
|
|
|
|
|
|
|
|
assert.Equal(t, "", ext.Name)
|
|
|
|
assert.Equal(t, "", ext.Clean)
|
|
|
|
assert.Equal(t, "", ext.Smudge)
|
|
|
|
assert.Equal(t, 0, ext.Priority)
|
|
|
|
}
|
2015-08-28 21:19:52 +00:00
|
|
|
|
2015-08-04 16:46:51 +00:00
|
|
|
func TestFetchPruneConfigDefault(t *testing.T) {
|
|
|
|
config := &Configuration{}
|
|
|
|
fp := config.FetchPruneConfig()
|
|
|
|
|
|
|
|
assert.Equal(t, 7, fp.FetchRecentRefsDays)
|
2015-08-17 11:04:43 +00:00
|
|
|
assert.Equal(t, 0, fp.FetchRecentCommitsDays)
|
2015-08-04 16:46:51 +00:00
|
|
|
assert.Equal(t, 3, fp.PruneOffsetDays)
|
2015-09-01 11:06:30 +00:00
|
|
|
assert.Equal(t, true, fp.FetchRecentRefsIncludeRemotes)
|
2015-08-04 16:46:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
func TestFetchPruneConfigCustom(t *testing.T) {
|
|
|
|
config := &Configuration{
|
|
|
|
gitConfig: map[string]string{
|
2015-08-17 15:28:26 +00:00
|
|
|
"lfs.fetchrecentrefsdays": "12",
|
2015-09-01 11:06:30 +00:00
|
|
|
"lfs.fetchrecentremoterefs": "false",
|
2015-08-17 15:28:26 +00:00
|
|
|
"lfs.fetchrecentcommitsdays": "9",
|
|
|
|
"lfs.pruneoffsetdays": "30",
|
2015-08-04 16:46:51 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
fp := config.FetchPruneConfig()
|
|
|
|
|
|
|
|
assert.Equal(t, 12, fp.FetchRecentRefsDays)
|
|
|
|
assert.Equal(t, 9, fp.FetchRecentCommitsDays)
|
|
|
|
assert.Equal(t, 30, fp.PruneOffsetDays)
|
2015-09-01 11:06:30 +00:00
|
|
|
assert.Equal(t, false, fp.FetchRecentRefsIncludeRemotes)
|
2015-09-01 18:32:55 +00:00
|
|
|
}
|
2015-08-04 16:46:51 +00:00
|
|
|
|
2015-08-28 21:19:52 +00:00
|
|
|
// only used for tests
|
|
|
|
func (c *Configuration) SetConfig(key, value string) {
|
|
|
|
if c.loadGitConfig() {
|
|
|
|
c.loading.Lock()
|
|
|
|
c.origConfig = make(map[string]string)
|
|
|
|
for k, v := range c.gitConfig {
|
|
|
|
c.origConfig[k] = v
|
|
|
|
}
|
|
|
|
c.loading.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
c.gitConfig[key] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Configuration) ResetConfig() {
|
|
|
|
c.loading.Lock()
|
|
|
|
c.gitConfig = make(map[string]string)
|
|
|
|
for k, v := range c.origConfig {
|
|
|
|
c.gitConfig[k] = v
|
|
|
|
}
|
|
|
|
c.loading.Unlock()
|
2015-08-04 16:46:51 +00:00
|
|
|
}
|