|
1 | 1 | package configparser_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "strings" |
5 | 6 |
|
6 | 7 | "github.com/bigkevmcd/go-configparser" |
@@ -101,6 +102,22 @@ func (s *ConfigParserSuite) TestGet(c *gc.C) { |
101 | 102 | c.Assert(result, gc.Equals, "200") |
102 | 103 | } |
103 | 104 |
|
| 105 | +func (s *ConfigParserSuite) TestGetConvError(c *gc.C) { |
| 106 | + p, err := configparser.NewWithDefaults( |
| 107 | + configparser.Dict{"key": "value"}, |
| 108 | + configparser.Converters( |
| 109 | + configparser.Converter{ |
| 110 | + configparser.StringConv: func(s string) (any, error) { |
| 111 | + return nil, errors.New("invalid string") |
| 112 | + }, |
| 113 | + }, |
| 114 | + ), |
| 115 | + ) |
| 116 | + c.Assert(err, gc.IsNil) |
| 117 | + _, err = p.Get("DEFAULT", "key") |
| 118 | + c.Assert(err, gc.ErrorMatches, "invalid string") |
| 119 | +} |
| 120 | + |
104 | 121 | // Get(section, option) should return the option value for the named section |
105 | 122 | // regardless of case |
106 | 123 | func (s *ConfigParserSuite) TestGetCamelCase(c *gc.C) { |
@@ -279,14 +296,14 @@ func (s *ConfigParserSuite) TestGetBool(c *gc.C) { |
279 | 296 | newParser := configparser.New() |
280 | 297 | newParser.AddSection("testing") |
281 | 298 |
|
282 | | - for _, value := range []string{"1", "yes", "true", "on"} { |
| 299 | + for _, value := range []string{"1", "yes", "true", "on", "True", "ON"} { |
283 | 300 | newParser.Set("testing", "value", value) |
284 | 301 | result, err := newParser.GetBool("testing", "value") |
285 | 302 | c.Assert(err, gc.IsNil) |
286 | 303 | c.Assert(result, gc.Equals, true) |
287 | 304 | } |
288 | 305 |
|
289 | | - for _, value := range []string{"0", "no", "false", "off"} { |
| 306 | + for _, value := range []string{"0", "no", "false", "off", "False", "OFF"} { |
290 | 307 | newParser.Set("testing", "value", value) |
291 | 308 | result, err := newParser.GetBool("testing", "value") |
292 | 309 | c.Assert(err, gc.IsNil) |
|
0 commit comments