()
| 207 | } |
| 208 | |
| 209 | func (r *SpecReader) validate() error { |
| 210 | if len(r.Sources) == 0 { |
| 211 | return errors.New("expecting at least one source") |
| 212 | } |
| 213 | if len(r.Destinations) == 0 { |
| 214 | return errors.New("expecting at least one destination") |
| 215 | } |
| 216 | |
| 217 | // here we check if source with different versions use the same destination and error out if yes |
| 218 | var destinationSourceMap = make(map[string]string) |
| 219 | for _, source := range r.Sources { |
| 220 | for _, destination := range source.Destinations { |
| 221 | if r.destinationsMap[destination] == nil { |
| 222 | return fmt.Errorf("source %s references unknown destination %s", source.Name, destination) |
| 223 | } |
| 224 | destinationToSourceKey := fmt.Sprintf("%s-%s", destination, source.Path) |
| 225 | if destinationSourceMap[destinationToSourceKey] == "" { |
| 226 | destinationSourceMap[destinationToSourceKey] = source.Path + "@" + source.Version |
| 227 | } else if destinationSourceMap[destinationToSourceKey] != source.Path+"@"+source.Version { |
| 228 | return fmt.Errorf("destination %s is used by multiple sources %s with different versions", destination, source.Path) |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | var err error |
| 234 | for _, destination := range r.Destinations { |
| 235 | if destination.SyncGroupId != "" && destination.WriteMode == WriteModeOverwriteDeleteStale { |
| 236 | err = errors.Join(err, fmt.Errorf("destination %s: sync_group_id is not supported with write_mode: %s", destination.Name, destination.WriteMode)) |
| 237 | } |
| 238 | for _, transformer := range destination.Transformers { |
| 239 | if r.transformersMap[transformer] == nil { |
| 240 | err = errors.Join(err, fmt.Errorf("destination %s references unknown transformer %s", destination.Name, transformer)) |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return err |
| 246 | } |
| 247 | |
| 248 | func (r *SpecReader) relaxedValidate() error { |
| 249 | if len(r.Sources) == 0 && len(r.Destinations) == 0 { |
no test coverage detected