(t *testing.T)
| 1574 | } |
| 1575 | |
| 1576 | func TestIsSet(t *testing.T) { |
| 1577 | v := New() |
| 1578 | v.SetConfigType("yaml") |
| 1579 | |
| 1580 | /* config and defaults */ |
| 1581 | v.ReadConfig(bytes.NewBuffer(yamlExample)) |
| 1582 | v.SetDefault("clothing.shoes", "sneakers") |
| 1583 | |
| 1584 | assert.True(t, v.IsSet("clothing")) |
| 1585 | assert.True(t, v.IsSet("clothing.jacket")) |
| 1586 | assert.False(t, v.IsSet("clothing.jackets")) |
| 1587 | assert.True(t, v.IsSet("clothing.shoes")) |
| 1588 | |
| 1589 | /* state change */ |
| 1590 | assert.False(t, v.IsSet("helloworld")) |
| 1591 | v.Set("helloworld", "fubar") |
| 1592 | assert.True(t, v.IsSet("helloworld")) |
| 1593 | |
| 1594 | /* env */ |
| 1595 | v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) |
| 1596 | v.BindEnv("eyes") |
| 1597 | v.BindEnv("foo") |
| 1598 | v.BindEnv("clothing.hat") |
| 1599 | v.BindEnv("clothing.hats") |
| 1600 | |
| 1601 | t.Setenv("FOO", "bar") |
| 1602 | t.Setenv("CLOTHING_HAT", "bowler") |
| 1603 | |
| 1604 | assert.True(t, v.IsSet("eyes")) // in the config file |
| 1605 | assert.True(t, v.IsSet("foo")) // in the environment |
| 1606 | assert.True(t, v.IsSet("clothing.hat")) // in the environment |
| 1607 | assert.False(t, v.IsSet("clothing.hats")) // not defined |
| 1608 | |
| 1609 | /* flags */ |
| 1610 | flagset := pflag.NewFlagSet("testisset", pflag.ContinueOnError) |
| 1611 | flagset.Bool("foobaz", false, "foobaz") |
| 1612 | flagset.Bool("barbaz", false, "barbaz") |
| 1613 | foobaz, barbaz := flagset.Lookup("foobaz"), flagset.Lookup("barbaz") |
| 1614 | v.BindPFlag("foobaz", foobaz) |
| 1615 | v.BindPFlag("barbaz", barbaz) |
| 1616 | barbaz.Value.Set("true") |
| 1617 | barbaz.Changed = true // hack for pflag usage |
| 1618 | |
| 1619 | assert.False(t, v.IsSet("foobaz")) |
| 1620 | assert.True(t, v.IsSet("barbaz")) |
| 1621 | } |
| 1622 | |
| 1623 | func TestDirsSearch(t *testing.T) { |
| 1624 | root, config := initDirs(t) |
nothing calls this directly
no test coverage detected