(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestInitConfig(t *testing.T) { |
| 200 | // Create a temporary file |
| 201 | tmpFile, err := os.CreateTemp("", "ledgerforge.json") |
| 202 | if err != nil { |
| 203 | t.Fatalf("Unable to create temporary file: %v", err) |
| 204 | } |
| 205 | defer os.Remove(tmpFile.Name()) // Clean up after the test |
| 206 | |
| 207 | // Sample configuration to write to the temp file |
| 208 | sampleConfig := Configuration{ |
| 209 | ProjectName: "InitConfig Test", |
| 210 | DataSource: DataSourceConfig{ |
| 211 | Dns: "init-config-dns", |
| 212 | }, Redis: RedisConfig{ |
| 213 | Dns: "localhost:6379", |
| 214 | }, |
| 215 | } |
| 216 | if err := json.NewEncoder(tmpFile).Encode(sampleConfig); err != nil { |
| 217 | t.Fatalf("Unable to write to temporary file: %v", err) |
| 218 | } |
| 219 | if err := tmpFile.Close(); err != nil { |
| 220 | t.Fatalf("Failed to close temp file: %v", err) |
| 221 | } // Close the file so InitConfig can open it |
| 222 | |
| 223 | // Attempt to initialize the configuration using the temporary file |
| 224 | if err := InitConfig(tmpFile.Name()); err != nil { |
| 225 | t.Fatalf("InitConfig failed: %v", err) |
| 226 | } |
| 227 | |
| 228 | // Fetch the loaded configuration to verify it was loaded correctly |
| 229 | loadedConfig, err := Fetch() |
| 230 | if err != nil { |
| 231 | t.Fatalf("Fetch failed: %v", err) |
| 232 | } |
| 233 | |
| 234 | // Verify the configuration was loaded correctly |
| 235 | if loadedConfig.ProjectName != "InitConfig Test" { |
| 236 | t.Errorf("Expected ProjectName to be 'InitConfig Test', got '%s'", loadedConfig.ProjectName) |
| 237 | } |
| 238 | if loadedConfig.DataSource.Dns != "init-config-dns" { |
| 239 | t.Errorf("Expected DataSource.Dns to be 'init-config-dns', got '%s'", loadedConfig.DataSource.Dns) |
| 240 | } |
| 241 | } |
nothing calls this directly
no test coverage detected