|
1 | 1 | package app |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
4 | 6 | "testing" |
5 | 7 |
|
6 | 8 | "github.com/stretchr/testify/assert" |
7 | 9 | "github.com/stretchr/testify/require" |
| 10 | + |
| 11 | + "github.com/stacklok/toolhive/pkg/runner" |
8 | 12 | ) |
9 | 13 |
|
10 | 14 | func TestRunCmdFlagsAndParsing(t *testing.T) { |
@@ -207,6 +211,35 @@ func TestRunWithFileBasedConfigBehavior(t *testing.T) { |
207 | 211 | k8sPodPatchFlag := cmd.Flag("k8s-pod-patch") |
208 | 212 | assert.NotNil(t, k8sPodPatchFlag, "k8s-pod-patch flag should exist for config file mode") |
209 | 213 | }) |
| 214 | + |
| 215 | + t.Run("EnvFileDir processing works with WithEnvFilesFromDirectory", func(t *testing.T) { |
| 216 | + t.Parallel() |
| 217 | + |
| 218 | + // This test verifies the pattern used in the fix for issue #2460 |
| 219 | + // It simulates what happens when Vault secrets are injected |
| 220 | + |
| 221 | + // Create temp directory with mock Vault secret files |
| 222 | + tmpDir := t.TempDir() |
| 223 | + err := os.WriteFile(filepath.Join(tmpDir, "api-key"), []byte("API_KEY=secret123"), 0644) |
| 224 | + require.NoError(t, err) |
| 225 | + err = os.WriteFile(filepath.Join(tmpDir, "db-password"), []byte("DB_PASSWORD=dbpass456"), 0644) |
| 226 | + require.NoError(t, err) |
| 227 | + |
| 228 | + // Create a RunConfig with EnvFileDir set (this is what the operator does) |
| 229 | + config := &runner.RunConfig{ |
| 230 | + EnvFileDir: tmpDir, |
| 231 | + EnvVars: map[string]string{"EXISTING": "value"}, |
| 232 | + } |
| 233 | + |
| 234 | + // Call WithEnvFilesFromDirectory (this is what the fix does) |
| 235 | + updatedConfig, err := config.WithEnvFilesFromDirectory(config.EnvFileDir) |
| 236 | + require.NoError(t, err) |
| 237 | + |
| 238 | + // Verify env vars from files were merged |
| 239 | + assert.Equal(t, "value", updatedConfig.EnvVars["EXISTING"], "Existing env var should be preserved") |
| 240 | + assert.Equal(t, "secret123", updatedConfig.EnvVars["API_KEY"], "API_KEY from file should be loaded") |
| 241 | + assert.Equal(t, "dbpass456", updatedConfig.EnvVars["DB_PASSWORD"], "DB_PASSWORD from file should be loaded") |
| 242 | + }) |
210 | 243 | } |
211 | 244 |
|
212 | 245 | func TestConfigFileModeIgnoresConfigFlags(t *testing.T) { |
|
0 commit comments