(t *testing.T)
| 280 | } |
| 281 | |
| 282 | func TestDatabaseConfig(t *testing.T) { |
| 283 | dir, err := os.MkdirTemp("", "garm-config-test") |
| 284 | if err != nil { |
| 285 | t.Fatalf("failed to create temporary directory: %s", err) |
| 286 | } |
| 287 | t.Cleanup(func() { os.RemoveAll(dir) }) |
| 288 | cfg := getDefaultDatabaseConfig(dir) |
| 289 | |
| 290 | tests := []struct { |
| 291 | name string |
| 292 | cfg Database |
| 293 | errString string |
| 294 | }{ |
| 295 | { |
| 296 | name: "Config is valid", |
| 297 | cfg: cfg, |
| 298 | errString: "", |
| 299 | }, |
| 300 | { |
| 301 | name: "Missing backend", |
| 302 | cfg: Database{ |
| 303 | DbBackend: "", |
| 304 | SQLite: cfg.SQLite, |
| 305 | Passphrase: cfg.Passphrase, |
| 306 | }, |
| 307 | errString: "invalid databse configuration: backend is required", |
| 308 | }, |
| 309 | { |
| 310 | name: "Invalid backend type", |
| 311 | cfg: Database{ |
| 312 | DbBackend: DBBackendType("bogus"), |
| 313 | SQLite: cfg.SQLite, |
| 314 | Passphrase: cfg.Passphrase, |
| 315 | }, |
| 316 | errString: "invalid database backend: bogus", |
| 317 | }, |
| 318 | { |
| 319 | name: "Missing passphrase", |
| 320 | cfg: Database{ |
| 321 | DbBackend: cfg.DbBackend, |
| 322 | SQLite: cfg.SQLite, |
| 323 | Passphrase: "", |
| 324 | }, |
| 325 | errString: "passphrase must be set and it must be a string of 32 characters*", |
| 326 | }, |
| 327 | { |
| 328 | name: "passphrase has invalid length", |
| 329 | cfg: Database{ |
| 330 | DbBackend: cfg.DbBackend, |
| 331 | SQLite: cfg.SQLite, |
| 332 | Passphrase: "testing", |
| 333 | }, |
| 334 | errString: "passphrase must be set and it must be a string of 32 characters*", |
| 335 | }, |
| 336 | { |
| 337 | name: "passphrase is too weak", |
| 338 | cfg: Database{ |
| 339 | DbBackend: cfg.DbBackend, |
nothing calls this directly
no test coverage detected