|
209 | 209 | (is (= "" (#'config/parse-dynamic-string "${env:UNDEFINED_VAR}" "/tmp"))) |
210 | 210 | (is (= "prefix suffix" (#'config/parse-dynamic-string "prefix ${env:UNDEFINED_VAR} suffix" "/tmp"))))) |
211 | 211 |
|
| 212 | + (testing "replaces undefined env var with default value" |
| 213 | + (with-redefs [config/get-env (constantly nil)] |
| 214 | + (is (= "default-value" (#'config/parse-dynamic-string "${env:UNDEFINED_VAR:default-value}" "/tmp"))) |
| 215 | + (is (= "http://localhost:11434" (#'config/parse-dynamic-string "${env:OLLAMA_API_URL:http://localhost:11434}" "/tmp"))) |
| 216 | + (is (= "prefix default-value suffix" (#'config/parse-dynamic-string "prefix ${env:UNDEFINED_VAR:default-value} suffix" "/tmp"))))) |
| 217 | + |
| 218 | + (testing "uses env var value when set, ignoring default" |
| 219 | + (with-redefs [config/get-env (fn [env-var] |
| 220 | + (case env-var |
| 221 | + "TEST_VAR" "actual-value" |
| 222 | + "OLLAMA_API_URL" "http://custom:8080" |
| 223 | + nil))] |
| 224 | + (is (= "actual-value" (#'config/parse-dynamic-string "${env:TEST_VAR:default-value}" "/tmp"))) |
| 225 | + (is (= "http://custom:8080" (#'config/parse-dynamic-string "${env:OLLAMA_API_URL:http://localhost:11434}" "/tmp"))))) |
| 226 | + |
| 227 | + (testing "handles default values with special characters" |
| 228 | + (with-redefs [config/get-env (constantly nil)] |
| 229 | + (is (= "http://localhost:11434/api" (#'config/parse-dynamic-string "${env:API_URL:http://localhost:11434/api}" "/tmp"))) |
| 230 | + (is (= "value-with-dashes" (#'config/parse-dynamic-string "${env:VAR:value-with-dashes}" "/tmp"))) |
| 231 | + (is (= "value_with_underscores" (#'config/parse-dynamic-string "${env:VAR:value_with_underscores}" "/tmp"))) |
| 232 | + (is (= "/path/to/file" (#'config/parse-dynamic-string "${env:VAR:/path/to/file}" "/tmp"))))) |
| 233 | + |
| 234 | + (testing "handles empty default value" |
| 235 | + (with-redefs [config/get-env (constantly nil)] |
| 236 | + (is (= "" (#'config/parse-dynamic-string "${env:UNDEFINED_VAR:}" "/tmp"))) |
| 237 | + (is (= "prefix suffix" (#'config/parse-dynamic-string "prefix ${env:UNDEFINED_VAR:} suffix" "/tmp"))))) |
| 238 | + |
| 239 | + (testing "handles multiple env vars with mixed default values" |
| 240 | + (with-redefs [config/get-env (fn [env-var] |
| 241 | + (case env-var |
| 242 | + "DEFINED_VAR" "defined" |
| 243 | + nil))] |
| 244 | + (is (= "defined and default-value" |
| 245 | + (#'config/parse-dynamic-string "${env:DEFINED_VAR:fallback1} and ${env:UNDEFINED_VAR:default-value}" "/tmp"))) |
| 246 | + (is (= "defined and " |
| 247 | + (#'config/parse-dynamic-string "${env:DEFINED_VAR} and ${env:UNDEFINED_VAR}" "/tmp"))))) |
| 248 | + |
212 | 249 | (testing "replaces file pattern with file content - absolute path" |
213 | 250 | (with-redefs [fs/absolute? (fn [path] (= path "/absolute/file.txt")) |
214 | 251 | slurp (fn [path] |
|
0 commit comments