Validate check if the Entity data is valid
()
| 365 | |
| 366 | // Validate check if the Entity data is valid |
| 367 | func (e *Entity) Validate() error { |
| 368 | // non-empty |
| 369 | if len(e.ops) == 0 && len(e.staging) == 0 { |
| 370 | return fmt.Errorf("entity has no operations") |
| 371 | } |
| 372 | |
| 373 | // check if each operation are valid |
| 374 | for _, op := range e.ops { |
| 375 | if err := op.Validate(); err != nil { |
| 376 | return err |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | // check if staging is valid if needed |
| 381 | for _, op := range e.staging { |
| 382 | if err := op.Validate(); err != nil { |
| 383 | return err |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | // Check that there is no colliding operation's ID |
| 388 | ids := make(map[entity.Id]struct{}) |
| 389 | for _, op := range e.Operations() { |
| 390 | if _, ok := ids[op.Id()]; ok { |
| 391 | return fmt.Errorf("id collision: %s", op.Id()) |
| 392 | } |
| 393 | ids[op.Id()] = struct{}{} |
| 394 | } |
| 395 | |
| 396 | return nil |
| 397 | } |
| 398 | |
| 399 | // Operations return the ordered operations |
| 400 | func (e *Entity) Operations() []Operation { |
no test coverage detected