@@ -2254,3 +2254,55 @@ func TestNoEnvKeyIgnored(t *testing.T) {
2254
2254
isEqual (t , "" , cfg .Foo )
2255
2255
isEqual (t , "202" , cfg .FooBar )
2256
2256
}
2257
+
2258
+ func TestIssue339 (t * testing.T ) {
2259
+ t .Run ("Should parse with bool ptr set and env undefined" , func (t * testing.T ) {
2260
+ existingValue := true
2261
+ cfg := Config {
2262
+ BoolPtr : & existingValue ,
2263
+ }
2264
+
2265
+ isNoErr (t , Parse (& cfg ))
2266
+
2267
+ isEqual (t , & existingValue , cfg .BoolPtr )
2268
+ })
2269
+
2270
+ t .Run ("Should parse with bool ptr set and env defined" , func (t * testing.T ) {
2271
+ existingValue := true
2272
+ cfg := Config {
2273
+ BoolPtr : & existingValue ,
2274
+ }
2275
+
2276
+ newValue := false
2277
+ t .Setenv ("BOOL" , strconv .FormatBool (newValue ))
2278
+
2279
+ isNoErr (t , Parse (& cfg ))
2280
+
2281
+ isEqual (t , & newValue , cfg .BoolPtr )
2282
+ })
2283
+
2284
+ t .Run ("Should parse with string ptr set and env undefined" , func (t * testing.T ) {
2285
+ existingValue := "one"
2286
+ cfg := Config {
2287
+ StringPtr : & existingValue ,
2288
+ }
2289
+
2290
+ isNoErr (t , Parse (& cfg ))
2291
+
2292
+ isEqual (t , & existingValue , cfg .StringPtr )
2293
+ })
2294
+
2295
+ t .Run ("Should parse with string ptr set and env defined" , func (t * testing.T ) {
2296
+ existingValue := "one"
2297
+ cfg := Config {
2298
+ StringPtr : & existingValue ,
2299
+ }
2300
+
2301
+ newValue := "two"
2302
+ t .Setenv ("STRING" , newValue )
2303
+
2304
+ isNoErr (t , Parse (& cfg ))
2305
+
2306
+ isEqual (t , & newValue , cfg .StringPtr )
2307
+ })
2308
+ }
0 commit comments