@@ -218,7 +218,7 @@ func TestSubstitutions(t *testing.T) {
218218 "OPTION_A" : "1" ,
219219 "OPTION_B" : "1" ,
220220 "OPTION_C" : "1" ,
221- "OPTION_D" : "11 " ,
221+ "OPTION_D" : "1_1 " ,
222222 "OPTION_E" : "" ,
223223 }
224224
@@ -614,19 +614,77 @@ func TestExpendingEnvironmentWithLookup(t *testing.T) {
614614 }
615615}
616616
617- func TestSubstitutionsWithShellEnvPrecedence (t * testing.T ) {
617+ func TestSubstitutionsWithEnvFilePrecedence (t * testing.T ) {
618618 os .Clearenv ()
619619 const envKey = "OPTION_A"
620620 const envVal = "5"
621621 os .Setenv (envKey , envVal )
622622 defer os .Unsetenv (envKey )
623623
624624 envFileName := "fixtures/substitutions.env"
625+ expectedValues := map [string ]string {
626+ "OPTION_A" : "1" ,
627+ "OPTION_B" : "1" ,
628+ "OPTION_C" : "1" ,
629+ "OPTION_D" : "1_1" ,
630+ "OPTION_E" : "" ,
631+ }
632+
633+ envMap , err := ReadWithLookup (os .LookupEnv , envFileName )
634+ if err != nil {
635+ t .Error ("Error reading file" )
636+ }
637+ if len (envMap ) != len (expectedValues ) {
638+ t .Error ("Didn't get the right size map back" )
639+ }
640+
641+ for key , value := range expectedValues {
642+ if envMap [key ] != value {
643+ t .Errorf ("Read got one of the keys wrong, [%q]->%q" , key , envMap [key ])
644+ }
645+ }
646+ }
647+
648+ func TestSubstitutionsWithEnvFileDefaultValuePrecedence (t * testing.T ) {
649+ os .Clearenv ()
650+ const envKey = "OPTION_A"
651+ const envVal = "5"
652+ os .Setenv (envKey , envVal )
653+ defer os .Unsetenv (envKey )
654+
655+ envFileName := "fixtures/substitutions-default.env"
625656 expectedValues := map [string ]string {
626657 "OPTION_A" : "5" ,
627658 "OPTION_B" : "5" ,
628659 "OPTION_C" : "5" ,
629- "OPTION_D" : "55" ,
660+ "OPTION_D" : "5_5" ,
661+ "OPTION_E" : "" ,
662+ }
663+
664+ envMap , err := ReadWithLookup (os .LookupEnv , envFileName )
665+ if err != nil {
666+ t .Error ("Error reading file" )
667+ }
668+ if len (envMap ) != len (expectedValues ) {
669+ t .Error ("Didn't get the right size map back" )
670+ }
671+
672+ for key , value := range expectedValues {
673+ if envMap [key ] != value {
674+ t .Errorf ("Read got one of the keys wrong, [%q]->%q" , key , envMap [key ])
675+ }
676+ }
677+ }
678+
679+ func TestSubstitutionsWithUnsetVarEnvFileDefaultValuePrecedence (t * testing.T ) {
680+ os .Clearenv ()
681+
682+ envFileName := "fixtures/substitutions-default.env"
683+ expectedValues := map [string ]string {
684+ "OPTION_A" : "1" ,
685+ "OPTION_B" : "1" ,
686+ "OPTION_C" : "1" ,
687+ "OPTION_D" : "1_1" ,
630688 "OPTION_E" : "" ,
631689 }
632690
0 commit comments