@@ -386,8 +386,13 @@ sub:
386386
387387 DescribeTable("LoadYAML",
388388 func(in loadYAMLTableInput) {
389− var configFileName string
389+ // Set the required environment variables before running the test
390+ os.Setenv("TESTUSER", "Alice")
391+
392+ // Unset the environment variables after running the test
393+ defer os.Unsetenv("TESTUSER")
390394
395+ var configFileName string
391396 if in.configFile != nil {
392397 By("Creating a config file")
393398 configFile, err := os.CreateTemp("", "oauth2-proxy-test-config-file")
@@ -407,12 +412,14 @@ sub:
407412 } else {
408413 input = &TestOptions{}
409414 }
415+
410416 err := LoadYAML(configFileName, input)
411417 if in.expectedErr != nil {
412418 Expect(err).To(MatchError(in.expectedErr.Error()))
413419 } else {
414420 Expect(err).ToNot(HaveOccurred())
415421 }
422+
416423 Expect(input).To(Equal(in.expectedOutput))
417424 },
418425 Entry("with a valid input", loadYAMLTableInput{
@@ -466,6 +473,20 @@ sub:
466473 expectedOutput: &TestOptions{},
467474 expectedErr: errors.New("error unmarshalling config: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go struct field TestOptions.StringSliceOption of type []string"),
468475 }),
476+ Entry("with a config file containing environment variable references", loadYAMLTableInput{
477+ configFile: []byte("stringOption: ${TESTUSER}"),
478+ input: &TestOptions{},
479+ expectedOutput: &TestOptions{
480+ StringOption: "Alice",
481+ },
482+ }),
483+ Entry("with a config file containing env variable references, with a fallback value", loadYAMLTableInput{
484+ configFile: []byte("stringOption: ${TESTUSER2=Bob}"),
485+ input: &TestOptions{},
486+ expectedOutput: &TestOptions{
487+ StringOption: "Bob",
488+ },
489+ }),
469490 )
470491 })
471492