6 . "github.com/git-lfs/git-lfs/config"
7 "github.com/stretchr/testify/assert"
10 func TestEnvironmentGetDelegatesToFetcher(t *testing.T) {
11 fetcher := MapFetcher(map[string][]string{
12 "foo": []string{"bar", "baz"},
15 env := EnvironmentOf(fetcher)
16 val, ok := env.Get("foo")
19 assert.Equal(t, "baz", val)
22 func TestEnvironmentGetAllDelegatesToFetcher(t *testing.T) {
23 fetcher := MapFetcher(map[string][]string{
24 "foo": []string{"bar", "baz"},
27 env := EnvironmentOf(fetcher)
28 vals := env.GetAll("foo")
30 assert.Equal(t, []string{"bar", "baz"}, vals)
33 func TestEnvironmentUnsetBoolDefault(t *testing.T) {
34 env := EnvironmentOf(MapFetcher(nil))
35 assert.True(t, env.Bool("unset", true))
38 func TestEnvironmentBoolTruthyConversion(t *testing.T) {
39 for _, c := range []EnvironmentConversionTestCase{
40 {"", false, GetBoolDefault(false)},
42 {"true", true, GetBoolDefault(false)},
43 {"1", true, GetBoolDefault(false)},
44 {"on", true, GetBoolDefault(false)},
45 {"yes", true, GetBoolDefault(false)},
46 {"t", true, GetBoolDefault(false)},
48 {"false", false, GetBoolDefault(true)},
49 {"0", false, GetBoolDefault(true)},
50 {"off", false, GetBoolDefault(true)},
51 {"no", false, GetBoolDefault(true)},
52 {"f", false, GetBoolDefault(true)},
58 func TestEnvironmentIntTestCases(t *testing.T) {
59 for _, c := range []EnvironmentConversionTestCase{
60 {"", 1, GetIntDefault(1)},
62 {"1", 1, GetIntDefault(0)},
63 {"3", 3, GetIntDefault(0)},
65 {"malformed", 7, GetIntDefault(7)},
71 type EnvironmentConversionTestCase struct {
75 GotFn func(env Environment, key string) interface{}
79 GetBoolDefault = func(def bool) func(e Environment, key string) interface{} {
80 return func(e Environment, key string) interface{} {
81 return e.Bool(key, def)
85 GetIntDefault = func(def int) func(e Environment, key string) interface{} {
86 return func(e Environment, key string) interface{} {
87 return e.Int(key, def)
92 func (c *EnvironmentConversionTestCase) Assert(t *testing.T) {
93 fetcher := MapFetcher(map[string][]string{
94 c.Val: []string{c.Val},
97 env := EnvironmentOf(fetcher)
98 got := c.GotFn(env, c.Val)
100 if c.Expected != got {
101 t.Errorf("lfs/config: expected val=%q to be %q (got: %q)", c.Val, c.Expected, got)