(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func TestValidateAndAddDefaults(t *testing.T) { |
| 26 | // Test case with empty ProjectName and DataSource DNS |
| 27 | cnf := Configuration{ |
| 28 | ProjectName: "", |
| 29 | DataSource: DataSourceConfig{ |
| 30 | Dns: "", |
| 31 | }, |
| 32 | Redis: RedisConfig{ |
| 33 | Dns: "localhost:6379", |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | err := cnf.validateAndAddDefaults() |
| 38 | if err == nil || err.Error() != "data source DNS is required" { |
| 39 | t.Errorf("Expected data source DNS required error, got %v", err) |
| 40 | } |
| 41 | cnf = Configuration{ |
| 42 | ProjectName: "", |
| 43 | DataSource: DataSourceConfig{ |
| 44 | Dns: "postgres://localhost:5432", |
| 45 | }, |
| 46 | Redis: RedisConfig{ |
| 47 | Dns: "", |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | err = cnf.validateAndAddDefaults() |
| 52 | if err == nil || err.Error() != "redis DNS is required" { |
| 53 | t.Errorf("Expected redis DNS required error, got %v", err) |
| 54 | } |
| 55 | // Test case with all required fields filled, expect no error |
| 56 | cnf = Configuration{ |
| 57 | ProjectName: "Test Project", |
| 58 | DataSource: DataSourceConfig{ |
| 59 | Dns: "some-dns", |
| 60 | }, |
| 61 | Redis: RedisConfig{ |
| 62 | Dns: "localhost:6379", |
| 63 | }, |
| 64 | } |
| 65 | |
| 66 | err = cnf.validateAndAddDefaults() |
| 67 | if err != nil { |
| 68 | t.Errorf("Expected no error, got %v", err) |
| 69 | } |
| 70 | |
| 71 | // Test default port setting |
| 72 | cnf.Server.Port = "" |
| 73 | err = cnf.validateAndAddDefaults() |
| 74 | if err != nil { |
| 75 | t.Errorf("Expected no error, got %v", err) |
| 76 | } |
| 77 | if cnf.Server.Port != DEFAULT_PORT { |
| 78 | t.Errorf("Expected default port %s, got %s", DEFAULT_PORT, cnf.Server.Port) |
| 79 | } |
| 80 | if cnf.Transaction.LockWaitTimeout != 3*time.Second { |
| 81 | t.Errorf("Expected default lock wait timeout %s, got %s", 3*time.Second, cnf.Transaction.LockWaitTimeout) |
| 82 | } |
nothing calls this directly
no test coverage detected