@@ -75,6 +75,9 @@ func TestReplace(t *testing.T) {
7575 // add some headers after creating replacer
7676 request .Header .Set ("CustomAdd" , "casket" )
7777 request .Header .Set ("Cookie" , "foo=bar; taste=delicious" )
78+ // add some environment variables
79+ os .Setenv ("TEST_ENV" , "test" )
80+ os .Setenv ("TEST_ENV_EMPTY" , "" )
7881
7982 // add some response headers
8083 recordRequest .Header ().Set ("Custom" , "CustomResponseHeader" )
@@ -108,6 +111,11 @@ func TestReplace(t *testing.T) {
108111 {"The Custom header is {>Custom}." , "The Custom header is foobarbaz." },
109112 {"The CustomAdd header is {>CustomAdd}." , "The CustomAdd header is casket." },
110113 {"The Custom response header is {<Custom}." , "The Custom response header is CustomResponseHeader." },
114+ {"The env variable TEST_ENV is {$TEST_ENV}." , "The env variable TEST_ENV is test." },
115+ {"The env variable TEST_ENV is {$TEST_ENV=default}, not default." , "The env variable TEST_ENV is test, not default." },
116+ {"The env variable TEST_ENV_EMPTY is {$TEST_ENV_EMPTY}." , "The env variable TEST_ENV_EMPTY is ." },
117+ {"The env variable TEST_ENV_EMPTY defaults to {$TEST_ENV_EMPTY=default}." , "The env variable TEST_ENV_EMPTY defaults to default." },
118+ {"The env variable NO_EXIST defaults to {$NO_EXIST=default}." , "The env variable NO_EXIST defaults to default." },
111119 {"Bad {>Custom placeholder" , "Bad {>Custom placeholder" },
112120 {"The request is {request}." , "The request is POST /?foo=bar HTTP/1.1\\ r\\ nHost: localhost.local\\ r\\ n" +
113121 "Cookie: foo=bar; taste=delicious\\ r\\ nCustom: foobarbaz\\ r\\ nCustomadd: casket\\ r\\ n" +
0 commit comments