77 "reflect"
88 "strings"
99 "testing"
10+
11+ "github.com/stretchr/testify/require"
1012)
1113
1214var noopPresets = make (map [string ]string )
@@ -131,7 +133,7 @@ func TestLoadDoesNotOverride(t *testing.T) {
131133 loadEnvAndCompareValues (t , Load , envFileName , expectedValues , presets )
132134}
133135
134- func TestOveroadDoesOverride (t * testing.T ) {
136+ func TestOverloadDoesOverride (t * testing.T ) {
135137 envFileName := "fixtures/plain.env"
136138
137139 // ensure NO overload
@@ -525,7 +527,7 @@ func TestRoundtrip(t *testing.T) {
525527 }
526528}
527529
528- func TestInheritedEnvVariablSameSize (t * testing.T ) {
530+ func TestInheritedEnvVariableSameSize (t * testing.T ) {
529531 const envKey = "VAR_TO_BE_LOADED_FROM_OS_ENV"
530532 const envVal = "SOME_RANDOM_VALUE"
531533 os .Setenv (envKey , envVal )
@@ -551,7 +553,7 @@ func TestInheritedEnvVariablSameSize(t *testing.T) {
551553 }
552554}
553555
554- func TestInheritedEnvVariablSingleVar (t * testing.T ) {
556+ func TestInheritedEnvVariableSingleVar (t * testing.T ) {
555557 const envKey = "VAR_TO_BE_LOADED_FROM_OS_ENV"
556558 const envVal = "SOME_RANDOM_VALUE"
557559 os .Setenv (envKey , envVal )
@@ -702,3 +704,25 @@ func TestSubstitutionsWithUnsetVarEnvFileDefaultValuePrecedence(t *testing.T) {
702704 }
703705 }
704706}
707+
708+ func TestUTF8BOM (t * testing.T ) {
709+ envFileName := "fixtures/utf8-bom.env"
710+
711+ // sanity check the fixture, since the UTF-8 BOM is invisible, it'd be
712+ // easy for it to get removed by accident, which would invalidate this
713+ // test
714+ envFileData , err := os .ReadFile (envFileName )
715+ require .NoError (t , err )
716+ require .True (t , bytes .HasPrefix (envFileData , []byte ("\uFEFF " )),
717+ "Test fixture file is missing UTF-8 BOM" )
718+
719+ expectedValues := map [string ]string {
720+ "OPTION_A" : "1" ,
721+ "OPTION_B" : "2" ,
722+ "OPTION_C" : "3" ,
723+ "OPTION_D" : "4" ,
724+ "OPTION_E" : "5" ,
725+ }
726+
727+ loadEnvAndCompareValues (t , Load , envFileName , expectedValues , noopPresets )
728+ }
0 commit comments