(t *testing.T)
| 363 | } |
| 364 | |
| 365 | func TestConfig_MergeWithFile(t *testing.T) { |
| 366 | // Create a temporary directory for test files |
| 367 | tempDir := t.TempDir() |
| 368 | |
| 369 | tests := []struct { |
| 370 | name string |
| 371 | initialConfig *Config |
| 372 | fileContent string |
| 373 | expectedConfig *Config |
| 374 | expectError bool |
| 375 | }{ |
| 376 | { |
| 377 | name: "merge with valid YAML file", |
| 378 | initialConfig: &Config{ |
| 379 | Addr: "https://initial.example.com:8006", |
| 380 | User: "initialuser", |
| 381 | }, |
| 382 | fileContent: ` |
| 383 | addr: "https://merged.example.com:8006" |
| 384 | password: "mergedpass" |
| 385 | debug: true |
| 386 | insecure: true |
| 387 | `, |
| 388 | expectedConfig: &Config{ |
| 389 | Addr: "https://merged.example.com:8006", |
| 390 | User: "initialuser", // Should keep initial value |
| 391 | Password: "mergedpass", |
| 392 | Debug: true, |
| 393 | Insecure: true, |
| 394 | }, |
| 395 | expectError: false, |
| 396 | }, |
| 397 | { |
| 398 | name: "merge with empty file path", |
| 399 | initialConfig: &Config{ |
| 400 | Addr: "https://initial.example.com:8006", |
| 401 | User: "initialuser", |
| 402 | }, |
| 403 | fileContent: "", |
| 404 | expectedConfig: &Config{ |
| 405 | Addr: "https://initial.example.com:8006", |
| 406 | User: "initialuser", |
| 407 | }, |
| 408 | expectError: false, |
| 409 | }, |
| 410 | { |
| 411 | name: "merge with invalid YAML", |
| 412 | initialConfig: &Config{ |
| 413 | Addr: "https://initial.example.com:8006", |
| 414 | }, |
| 415 | fileContent: ` |
| 416 | invalid: yaml: content: |
| 417 | - malformed |
| 418 | `, |
| 419 | expectError: true, |
| 420 | }, |
| 421 | } |
| 422 |
nothing calls this directly
no test coverage detected