(t *testing.T)
| 2240 | } |
| 2241 | |
| 2242 | func TestSetDefaultsForZeroValuesOnly(t *testing.T) { |
| 2243 | type config struct { |
| 2244 | Str string `env:"STR" envDefault:"foo"` |
| 2245 | Int int `env:"INT" envDefault:"42"` |
| 2246 | URL url.URL `env:"URL" envDefault:"https://github.com/caarlos0"` |
| 2247 | } |
| 2248 | defURL, err := url.Parse("https://github.com/caarlos0") |
| 2249 | isNoErr(t, err) |
| 2250 | |
| 2251 | u, err := url.Parse("https://localhost/foo") |
| 2252 | isNoErr(t, err) |
| 2253 | |
| 2254 | for _, tc := range []struct { |
| 2255 | Name string |
| 2256 | Options Options |
| 2257 | Expected config |
| 2258 | }{ |
| 2259 | { |
| 2260 | Name: "true", |
| 2261 | Options: Options{SetDefaultsForZeroValuesOnly: true}, |
| 2262 | Expected: config{ |
| 2263 | Str: "isSet", |
| 2264 | Int: 1, |
| 2265 | URL: *u, |
| 2266 | }, |
| 2267 | }, |
| 2268 | { |
| 2269 | Name: "false", |
| 2270 | Options: Options{SetDefaultsForZeroValuesOnly: false}, |
| 2271 | Expected: config{ |
| 2272 | Str: "foo", |
| 2273 | Int: 42, |
| 2274 | URL: *defURL, |
| 2275 | }, |
| 2276 | }, |
| 2277 | { |
| 2278 | Name: "default", |
| 2279 | Options: Options{}, |
| 2280 | Expected: config{ |
| 2281 | Str: "foo", |
| 2282 | Int: 42, |
| 2283 | URL: *defURL, |
| 2284 | }, |
| 2285 | }, |
| 2286 | } { |
| 2287 | t.Run(tc.Name, func(t *testing.T) { |
| 2288 | cfg := &config{ |
| 2289 | Str: "isSet", |
| 2290 | Int: 1, |
| 2291 | URL: *u, |
| 2292 | } |
| 2293 | isNoErr(t, ParseWithOptions(cfg, tc.Options)) |
| 2294 | isEqual(t, tc.Expected, *cfg) |
| 2295 | }) |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | func TestParseWithOptionsRenamedPrefix(t *testing.T) { |
nothing calls this directly
no test coverage detected