-
Notifications
You must be signed in to change notification settings - Fork 346
Expand file tree
/
Copy pathconfig_test.go
More file actions
42 lines (35 loc) · 1.04 KB
/
Copy pathconfig_test.go
File metadata and controls
42 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"os"
"path/filepath"
"testing"
)
func TestLoadConfig(t *testing.T) {
// Create a temp config file
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "config.conf")
content := `# This is a comment
AI_PROVIDER=deepseek
TEST_KEY_FROM_CONFIG=hello
# Another comment
EXISTING_ENV_VAR=new_val
`
err := os.WriteFile(configPath, []byte(content), 0644)
if err != nil {
t.Fatalf("failed to write temp config file: %v", err)
}
os.Setenv("EXISTING_ENV_VAR", "original_val")
defer os.Unsetenv("EXISTING_ENV_VAR")
defer os.Unsetenv("AI_PROVIDER")
defer os.Unsetenv("TEST_KEY_FROM_CONFIG")
loadConfig(configPath)
if val := os.Getenv("AI_PROVIDER"); val != "deepseek" {
t.Errorf("expected AI_PROVIDER=deepseek, got %q", val)
}
if val := os.Getenv("TEST_KEY_FROM_CONFIG"); val != "hello" {
t.Errorf("expected TEST_KEY_FROM_CONFIG=hello, got %q", val)
}
if val := os.Getenv("EXISTING_ENV_VAR"); val != "original_val" {
t.Errorf("expected EXISTING_ENV_VAR to remain original_val, got %q", val)
}
}