add some Access() tests

This commit is contained in:
Rick Olson 2015-09-02 13:03:37 -06:00
parent ae233608a7
commit 1eda75a35d
2 changed files with 45 additions and 1 deletions

@ -161,7 +161,11 @@ func (c *Configuration) SetAccess(authType string) {
func (c *Configuration) EndpointAccess(e Endpoint) string { func (c *Configuration) EndpointAccess(e Endpoint) string {
key := fmt.Sprintf("lfs.%s.access", e.Url) key := fmt.Sprintf("lfs.%s.access", e.Url)
if v, ok := c.GitConfig(key); ok && len(v) > 0 { if v, ok := c.GitConfig(key); ok && len(v) > 0 {
return strings.ToLower(v) lower := strings.ToLower(v)
if lower == "private" {
return "basic"
}
return lower
} }
return "none" return "none"
} }

@ -309,6 +309,46 @@ func TestBatchAbsentIsTrue(t *testing.T) {
assert.Equal(t, true, v) assert.Equal(t, true, v)
} }
func TestAccessConfig(t *testing.T) {
type accessTest struct {
Access string
PrivateAccess bool
}
tests := map[string]accessTest{
"": {"none", false},
"basic": {"basic", true},
"BASIC": {"basic", true},
"private": {"basic", true},
"PRIVATE": {"basic", true},
"invalidauth": {"invalidauth", true},
}
for value, expected := range tests {
config := &Configuration{
gitConfig: map[string]string{
"lfs.url": "http://example.com",
"lfs.http://example.com.access": value,
"lfs.https://example.com.access": "bad",
},
}
if access := config.Access(); access != expected.Access {
t.Errorf("Expected Access() with value %q to be %v, got %v", value, expected.Access, access)
}
if priv := config.PrivateAccess(); priv != expected.PrivateAccess {
t.Errorf("Expected PrivateAccess() with value %q to be %v, got %v", value, expected.PrivateAccess, priv)
}
}
}
func TestAccessAbsentConfig(t *testing.T) {
config := &Configuration{}
assert.Equal(t, "none", config.Access())
assert.Equal(t, false, config.PrivateAccess())
}
func TestLoadValidExtension(t *testing.T) { func TestLoadValidExtension(t *testing.T) {
config := &Configuration{ config := &Configuration{
gitConfig: map[string]string{}, gitConfig: map[string]string{},