github.com/stffabi/git-lfs@v2.3.5-0.20180214015214-8eeaa8d88902+incompatible/config/config_test.go (about) 1 package config 2 3 import ( 4 "testing" 5 6 "github.com/git-lfs/git-lfs/git" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestRemoteDefault(t *testing.T) { 11 cfg := NewFrom(Values{ 12 Git: map[string][]string{ 13 "branch.unused.remote": []string{"a"}, 14 "branch.unused.pushRemote": []string{"b"}, 15 }, 16 }) 17 assert.Equal(t, "origin", cfg.Remote()) 18 assert.Equal(t, "origin", cfg.PushRemote()) 19 } 20 21 func TestRemoteBranchConfig(t *testing.T) { 22 cfg := NewFrom(Values{ 23 Git: map[string][]string{ 24 "branch.master.remote": []string{"a"}, 25 "branch.other.pushRemote": []string{"b"}, 26 }, 27 }) 28 cfg.ref = &git.Ref{Name: "master"} 29 30 assert.Equal(t, "a", cfg.Remote()) 31 assert.Equal(t, "a", cfg.PushRemote()) 32 } 33 34 func TestRemotePushDefault(t *testing.T) { 35 cfg := NewFrom(Values{ 36 Git: map[string][]string{ 37 "branch.master.remote": []string{"a"}, 38 "remote.pushDefault": []string{"b"}, 39 "branch.other.pushRemote": []string{"c"}, 40 }, 41 }) 42 cfg.ref = &git.Ref{Name: "master"} 43 44 assert.Equal(t, "a", cfg.Remote()) 45 assert.Equal(t, "b", cfg.PushRemote()) 46 } 47 48 func TestRemoteBranchPushDefault(t *testing.T) { 49 cfg := NewFrom(Values{ 50 Git: map[string][]string{ 51 "branch.master.remote": []string{"a"}, 52 "remote.pushDefault": []string{"b"}, 53 "branch.master.pushRemote": []string{"c"}, 54 }, 55 }) 56 cfg.ref = &git.Ref{Name: "master"} 57 58 assert.Equal(t, "a", cfg.Remote()) 59 assert.Equal(t, "c", cfg.PushRemote()) 60 } 61 62 func TestBasicTransfersOnlySetValue(t *testing.T) { 63 cfg := NewFrom(Values{ 64 Git: map[string][]string{ 65 "lfs.basictransfersonly": []string{"true"}, 66 }, 67 }) 68 69 b := cfg.BasicTransfersOnly() 70 assert.Equal(t, true, b) 71 } 72 73 func TestBasicTransfersOnlyDefault(t *testing.T) { 74 cfg := NewFrom(Values{}) 75 76 b := cfg.BasicTransfersOnly() 77 assert.Equal(t, false, b) 78 } 79 80 func TestBasicTransfersOnlyInvalidValue(t *testing.T) { 81 cfg := NewFrom(Values{ 82 Git: map[string][]string{ 83 "lfs.basictransfersonly": []string{"wat"}, 84 }, 85 }) 86 87 b := cfg.BasicTransfersOnly() 88 assert.Equal(t, false, b) 89 } 90 91 func TestTusTransfersAllowedSetValue(t *testing.T) { 92 cfg := NewFrom(Values{ 93 Git: map[string][]string{ 94 "lfs.tustransfers": []string{"true"}, 95 }, 96 }) 97 98 b := cfg.TusTransfersAllowed() 99 assert.Equal(t, true, b) 100 } 101 102 func TestTusTransfersAllowedDefault(t *testing.T) { 103 cfg := NewFrom(Values{}) 104 105 b := cfg.TusTransfersAllowed() 106 assert.Equal(t, false, b) 107 } 108 109 func TestTusTransfersAllowedInvalidValue(t *testing.T) { 110 cfg := NewFrom(Values{ 111 Git: map[string][]string{ 112 "lfs.tustransfers": []string{"wat"}, 113 }, 114 }) 115 116 b := cfg.TusTransfersAllowed() 117 assert.Equal(t, false, b) 118 } 119 120 func TestLoadValidExtension(t *testing.T) { 121 cfg := NewFrom(Values{ 122 Git: map[string][]string{ 123 "lfs.extension.foo.clean": []string{"foo-clean %f"}, 124 "lfs.extension.foo.smudge": []string{"foo-smudge %f"}, 125 "lfs.extension.foo.priority": []string{"2"}, 126 }, 127 }) 128 129 ext := cfg.Extensions()["foo"] 130 131 assert.Equal(t, "foo", ext.Name) 132 assert.Equal(t, "foo-clean %f", ext.Clean) 133 assert.Equal(t, "foo-smudge %f", ext.Smudge) 134 assert.Equal(t, 2, ext.Priority) 135 } 136 137 func TestLoadInvalidExtension(t *testing.T) { 138 cfg := NewFrom(Values{}) 139 ext := cfg.Extensions()["foo"] 140 141 assert.Equal(t, "", ext.Name) 142 assert.Equal(t, "", ext.Clean) 143 assert.Equal(t, "", ext.Smudge) 144 assert.Equal(t, 0, ext.Priority) 145 } 146 147 func TestFetchIncludeExcludesAreCleaned(t *testing.T) { 148 cfg := NewFrom(Values{ 149 Git: map[string][]string{ 150 "lfs.fetchinclude": []string{"/path/to/clean/"}, 151 "lfs.fetchexclude": []string{"/other/path/to/clean/"}, 152 }, 153 }) 154 155 assert.Equal(t, []string{"/path/to/clean"}, cfg.FetchIncludePaths()) 156 assert.Equal(t, []string{"/other/path/to/clean"}, cfg.FetchExcludePaths()) 157 }