(current, proposed *WorkerAssignment)
| 190 | } |
| 191 | |
| 192 | func resolveWorkerAssignment(current, proposed *WorkerAssignment) (*WorkerAssignment, error) { |
| 193 | if current != nil { |
| 194 | if err := validateWorkerAssignment(current); err != nil { |
| 195 | return nil, fmt.Errorf("current assignment: %w", err) |
| 196 | } |
| 197 | } |
| 198 | if proposed != nil { |
| 199 | if err := validateWorkerAssignment(proposed); err != nil { |
| 200 | return nil, fmt.Errorf("proposed assignment: %w", err) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | switch { |
| 205 | case current == nil && proposed == nil: |
| 206 | return nil, fmt.Errorf("assignment is required") |
| 207 | case current == nil: |
| 208 | return cloneWorkerAssignment(proposed), nil |
| 209 | case proposed == nil: |
| 210 | return cloneWorkerAssignment(current), nil |
| 211 | case current.OrgID != proposed.OrgID: |
| 212 | return nil, fmt.Errorf("assignment org cannot change from %q to %q", current.OrgID, proposed.OrgID) |
| 213 | default: |
| 214 | return cloneWorkerAssignment(proposed), nil |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | func validateWorkerAssignment(assignment *WorkerAssignment) error { |
| 219 | if assignment == nil { |
no test coverage detected