(t *testing.T)
| 41 | } |
| 42 | |
| 43 | func TestExpandVariables(t *testing.T) { |
| 44 | // Set test environment variables |
| 45 | _ = os.Setenv("TEST_VAR", "test_value") |
| 46 | _ = os.Setenv("ANOTHER_VAR", "another_value") |
| 47 | defer func() { _ = os.Unsetenv("TEST_VAR") }() |
| 48 | defer func() { _ = os.Unsetenv("ANOTHER_VAR") }() |
| 49 | |
| 50 | loader := NewLoader() |
| 51 | |
| 52 | tests := []struct { |
| 53 | name string |
| 54 | input string |
| 55 | expected string |
| 56 | }{ |
| 57 | { |
| 58 | name: "simple variable", |
| 59 | input: "${TEST_VAR}", |
| 60 | expected: "test_value", |
| 61 | }, |
| 62 | { |
| 63 | name: "variable with default - exists", |
| 64 | input: "${TEST_VAR:-default}", |
| 65 | expected: "test_value", |
| 66 | }, |
| 67 | { |
| 68 | name: "variable with default - not exists", |
| 69 | input: "${NONEXISTENT:-default_value}", |
| 70 | expected: "default_value", |
| 71 | }, |
| 72 | { |
| 73 | name: "simple dollar variable", |
| 74 | input: "$TEST_VAR", |
| 75 | expected: "test_value", |
| 76 | }, |
| 77 | { |
| 78 | name: "mixed content", |
| 79 | input: "prefix_${TEST_VAR}_suffix", |
| 80 | expected: "prefix_test_value_suffix", |
| 81 | }, |
| 82 | { |
| 83 | name: "multiple variables", |
| 84 | input: "${TEST_VAR}_${ANOTHER_VAR}", |
| 85 | expected: "test_value_another_value", |
| 86 | }, |
| 87 | { |
| 88 | name: "no variables", |
| 89 | input: "plain text", |
| 90 | expected: "plain text", |
| 91 | }, |
| 92 | { |
| 93 | name: "nonexistent variable", |
| 94 | input: "${DOES_NOT_EXIST}", |
| 95 | expected: "", |
| 96 | }, |
| 97 | } |
| 98 | |
| 99 | for _, tt := range tests { |
| 100 | t.Run(tt.name, func(t *testing.T) { |
nothing calls this directly
no test coverage detected