Validate check if the Bug data is valid
()
| 85 | |
| 86 | // Validate check if the Bug data is valid |
| 87 | func (bug *Bug) Validate() error { |
| 88 | if err := bug.Entity.Validate(); err != nil { |
| 89 | return err |
| 90 | } |
| 91 | |
| 92 | // The very first Op should be a CreateOp |
| 93 | firstOp := bug.FirstOp() |
| 94 | if firstOp == nil || firstOp.Type() != CreateOp { |
| 95 | return fmt.Errorf("first operation should be a Create op") |
| 96 | } |
| 97 | |
| 98 | // Check that there is no more CreateOp op |
| 99 | for i, op := range bug.Entity.Operations() { |
| 100 | if i == 0 { |
| 101 | continue |
| 102 | } |
| 103 | if op.Type() == CreateOp { |
| 104 | return fmt.Errorf("only one Create op allowed") |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return nil |
| 109 | } |
| 110 | |
| 111 | // Append add a new Operation to the Bug |
| 112 | func (bug *Bug) Append(op Operation) { |
nothing calls this directly
no test coverage detected