git-lfs/lfs/config_test.go

195 lines
5.4 KiB
Go
Raw Normal View History

2015-03-19 19:30:55 +00:00
package lfs
2014-02-01 21:09:52 +00:00
import (
"github.com/bmizerany/assert"
"testing"
)
func TestEndpointDefaultsToOrigin(t *testing.T) {
config := &Configuration{
gitConfig: map[string]string{"remote.origin.lfs_url": "abc"},
2015-01-12 00:53:10 +00:00
remotes: []string{},
2014-02-01 21:09:52 +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{
"lfs.url": "abc",
"remote.origin.lfs_url": "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
}
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
func TestEndpointNoOverrideDefaultRemote(t *testing.T) {
config := &Configuration{
gitConfig: map[string]string{
"remote.origin.lfs_url": "abc",
"remote.other.lfs_url": "def",
},
remotes: []string{},
}
endpoint := config.Endpoint()
assert.Equal(t, "abc", endpoint.Url)
assert.Equal(t, "", endpoint.SshUserAndHost)
assert.Equal(t, "", endpoint.SshPath)
}
func TestEndpointUseAlternateRemote(t *testing.T) {
config := &Configuration{
gitConfig: map[string]string{
"remote.origin.lfs_url": "abc",
"remote.other.lfs_url": "def",
},
remotes: []string{},
}
config.CurrentRemote = "other"
endpoint := config.Endpoint()
assert.Equal(t, "def", endpoint.Url)
assert.Equal(t, "", endpoint.SshUserAndHost)
assert.Equal(t, "", endpoint.SshPath)
}
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
}
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
}
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{
"remote.origin.url": "git@example.com:foo/bar",
"remote.origin.lfs_url": "lfs",
},
remotes: []string{},
}
endpoint := config.Endpoint()
assert.Equal(t, "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 TestSSHEndpointAddsLfsSuffix(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"},
remotes: []string{},
2014-05-22 23:02:56 +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)
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
}
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)
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
}
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)
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
}
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)
2014-05-22 23:02:56 +00:00
}
2015-02-13 23:25:05 +00:00
func TestObjectUrl(t *testing.T) {
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) {
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())
}
}
}
}