| 92 | } |
| 93 | |
| 94 | func TestInit_APIEndpoint(t *testing.T) { |
| 95 | // Create a temporary directory for test |
| 96 | tmpDir, err := os.MkdirTemp("", "dnote-init-test-*") |
| 97 | if err != nil { |
| 98 | t.Fatal(errors.Wrap(err, "creating temp dir")) |
| 99 | } |
| 100 | defer os.RemoveAll(tmpDir) |
| 101 | |
| 102 | // Set up environment to use our temp directory |
| 103 | t.Setenv("XDG_CONFIG_HOME", fmt.Sprintf("%s/config", tmpDir)) |
| 104 | t.Setenv("XDG_DATA_HOME", fmt.Sprintf("%s/data", tmpDir)) |
| 105 | t.Setenv("XDG_CACHE_HOME", fmt.Sprintf("%s/cache", tmpDir)) |
| 106 | |
| 107 | // Force dirs package to reload with new environment |
| 108 | dirs.Reload() |
| 109 | |
| 110 | // Initialize - should create config with default apiEndpoint |
| 111 | ctx, err := Init("test-version", "", "") |
| 112 | if err != nil { |
| 113 | t.Fatal(errors.Wrap(err, "initializing")) |
| 114 | } |
| 115 | defer ctx.DB.Close() |
| 116 | |
| 117 | // Read the config that was created |
| 118 | cf, err := config.Read(*ctx) |
| 119 | if err != nil { |
| 120 | t.Fatal(errors.Wrap(err, "reading config")) |
| 121 | } |
| 122 | |
| 123 | // Context should use the apiEndpoint from config |
| 124 | assert.Equal(t, ctx.APIEndpoint, DefaultAPIEndpoint, "context should use apiEndpoint from config") |
| 125 | assert.Equal(t, cf.APIEndpoint, DefaultAPIEndpoint, "context should use apiEndpoint from config") |
| 126 | } |