@@ -214,6 +214,18 @@ type Button struct {
214
214
215
215
type Base64ByteSlice []Base64Bytes
216
216
217
+ func boolPtr (b bool ) * bool {
218
+ return & b
219
+ }
220
+
221
+ func stringPtr (s string ) * string {
222
+ return & s
223
+ }
224
+
225
+ func intPtr (i int ) * int {
226
+ return & i
227
+ }
228
+
217
229
func TestProcessWith (t * testing.T ) {
218
230
t .Parallel ()
219
231
@@ -1445,35 +1457,49 @@ func TestProcessWith(t *testing.T) {
1445
1457
1446
1458
// Pointer pointers
1447
1459
{
1448
- name : "string_pointer " ,
1460
+ name : "pointer_string " ,
1449
1461
input : & struct {
1450
1462
Field * string `env:"FIELD"`
1451
1463
}{},
1452
1464
exp : & struct {
1453
1465
Field * string `env:"FIELD"`
1454
1466
}{
1455
- Field : func () * string { s := "foo" ; return & s }( ),
1467
+ Field : stringPtr ( "foo" ),
1456
1468
},
1457
1469
lookuper : MapLookuper (map [string ]string {
1458
1470
"FIELD" : "foo" ,
1459
1471
}),
1460
1472
},
1461
1473
{
1462
- name : "string_pointer_pointer " ,
1474
+ name : "pointer_pointer_string " ,
1463
1475
input : & struct {
1464
1476
Field * * string `env:"FIELD"`
1465
1477
}{},
1466
1478
exp : & struct {
1467
1479
Field * * string `env:"FIELD"`
1468
1480
}{
1469
- Field : func () * * string { s := "foo" ; ptr := & s ; return & ptr }(),
1481
+ Field : func () * * string { ptr := stringPtr ( "foo" ) ; return & ptr }(),
1470
1482
},
1471
1483
lookuper : MapLookuper (map [string ]string {
1472
1484
"FIELD" : "foo" ,
1473
1485
}),
1474
1486
},
1475
1487
{
1476
- name : "map_pointer" ,
1488
+ name : "pointer_int" ,
1489
+ input : & struct {
1490
+ Field * int `env:"FIELD"`
1491
+ }{},
1492
+ exp : & struct {
1493
+ Field * int `env:"FIELD"`
1494
+ }{
1495
+ Field : intPtr (5 ),
1496
+ },
1497
+ lookuper : MapLookuper (map [string ]string {
1498
+ "FIELD" : "5" ,
1499
+ }),
1500
+ },
1501
+ {
1502
+ name : "pointer_map" ,
1477
1503
input : & struct {
1478
1504
Field * map [string ]string `env:"FIELD"`
1479
1505
}{},
@@ -1490,7 +1516,7 @@ func TestProcessWith(t *testing.T) {
1490
1516
}),
1491
1517
},
1492
1518
{
1493
- name : "slice_pointer " ,
1519
+ name : "pointer_slice " ,
1494
1520
input : & struct {
1495
1521
Field * []string `env:"FIELD"`
1496
1522
}{},
@@ -1507,7 +1533,21 @@ func TestProcessWith(t *testing.T) {
1507
1533
}),
1508
1534
},
1509
1535
{
1510
- name : "bool_pointer" ,
1536
+ name : "pointer_bool" ,
1537
+ input : & struct {
1538
+ Field * bool `env:"FIELD"`
1539
+ }{},
1540
+ exp : & struct {
1541
+ Field * bool `env:"FIELD"`
1542
+ }{
1543
+ Field : boolPtr (true ),
1544
+ },
1545
+ lookuper : MapLookuper (map [string ]string {
1546
+ "FIELD" : "true" ,
1547
+ }),
1548
+ },
1549
+ {
1550
+ name : "pointer_bool_noinit" ,
1511
1551
input : & struct {
1512
1552
Field * bool `env:"FIELD,noinit"`
1513
1553
}{},
@@ -1518,6 +1558,118 @@ func TestProcessWith(t *testing.T) {
1518
1558
},
1519
1559
lookuper : MapLookuper (nil ),
1520
1560
},
1561
+ {
1562
+ name : "pointer_bool_default_field_set_env_unset" ,
1563
+ input : & struct {
1564
+ Field * bool `env:"FIELD,default=true"`
1565
+ }{
1566
+ Field : boolPtr (false ),
1567
+ },
1568
+ exp : & struct {
1569
+ Field * bool `env:"FIELD,default=true"`
1570
+ }{
1571
+ Field : boolPtr (false ),
1572
+ },
1573
+ lookuper : MapLookuper (nil ),
1574
+ },
1575
+ {
1576
+ name : "pointer_bool_default_field_set_env_set" ,
1577
+ input : & struct {
1578
+ Field * bool `env:"FIELD,default=true"`
1579
+ }{
1580
+ Field : boolPtr (false ),
1581
+ },
1582
+ exp : & struct {
1583
+ Field * bool `env:"FIELD,default=true"`
1584
+ }{
1585
+ Field : boolPtr (false ),
1586
+ },
1587
+ lookuper : MapLookuper (map [string ]string {
1588
+ "FIELD" : "true" ,
1589
+ }),
1590
+ },
1591
+ {
1592
+ name : "pointer_bool_default_field_unset_env_set" ,
1593
+ input : & struct {
1594
+ Field * bool `env:"FIELD,default=true"`
1595
+ }{},
1596
+ exp : & struct {
1597
+ Field * bool `env:"FIELD,default=true"`
1598
+ }{
1599
+ Field : boolPtr (false ),
1600
+ },
1601
+ lookuper : MapLookuper (map [string ]string {
1602
+ "FIELD" : "false" ,
1603
+ }),
1604
+ },
1605
+ {
1606
+ name : "pointer_bool_default_field_unset_env_unset" ,
1607
+ input : & struct {
1608
+ Field * bool `env:"FIELD,default=true"`
1609
+ }{},
1610
+ exp : & struct {
1611
+ Field * bool `env:"FIELD,default=true"`
1612
+ }{
1613
+ Field : boolPtr (true ),
1614
+ },
1615
+ lookuper : MapLookuper (nil ),
1616
+ },
1617
+ {
1618
+ name : "pointer_bool_default_overwrite_field_set_env_unset" ,
1619
+ input : & struct {
1620
+ Field * bool `env:"FIELD,overwrite,default=true"`
1621
+ }{
1622
+ Field : boolPtr (false ),
1623
+ },
1624
+ exp : & struct {
1625
+ Field * bool `env:"FIELD,overwrite,default=true"`
1626
+ }{
1627
+ Field : boolPtr (false ),
1628
+ },
1629
+ lookuper : MapLookuper (nil ),
1630
+ },
1631
+ {
1632
+ name : "pointer_bool_default_overwrite_field_set_env_set" ,
1633
+ input : & struct {
1634
+ Field * bool `env:"FIELD,overwrite,default=true"`
1635
+ }{
1636
+ Field : boolPtr (false ),
1637
+ },
1638
+ exp : & struct {
1639
+ Field * bool `env:"FIELD,overwrite,default=true"`
1640
+ }{
1641
+ Field : boolPtr (true ),
1642
+ },
1643
+ lookuper : MapLookuper (map [string ]string {
1644
+ "FIELD" : "true" ,
1645
+ }),
1646
+ },
1647
+ {
1648
+ name : "pointer_bool_default_overwrite_field_unset_env_set" ,
1649
+ input : & struct {
1650
+ Field * bool `env:"FIELD,overwrite,default=true"`
1651
+ }{},
1652
+ exp : & struct {
1653
+ Field * bool `env:"FIELD,overwrite,default=true"`
1654
+ }{
1655
+ Field : boolPtr (false ),
1656
+ },
1657
+ lookuper : MapLookuper (map [string ]string {
1658
+ "FIELD" : "false" ,
1659
+ }),
1660
+ },
1661
+ {
1662
+ name : "pointer_bool_default_overwrite_field_unset_env_unset" ,
1663
+ input : & struct {
1664
+ Field * bool `env:"FIELD,overwrite,default=true"`
1665
+ }{},
1666
+ exp : & struct {
1667
+ Field * bool `env:"FIELD,overwrite,default=true"`
1668
+ }{
1669
+ Field : boolPtr (true ),
1670
+ },
1671
+ lookuper : MapLookuper (nil ),
1672
+ },
1521
1673
1522
1674
// Marshallers
1523
1675
{
0 commit comments