Guest User

Untitled

a guest
Dec 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. func (c *backupController) run(backup *v1.Backup) error {
  2. var errs []error
  3.  
  4. // shallow copy to backup so we can generate a patch
  5. var original := backup
  6. // deep copy so we don't mutate original
  7. backup = backup.DeepCopy()
  8.  
  9. file, _ := ioutil.TempFile("", "")
  10. defer file.Close()
  11.  
  12. // May mutate backup.Status.Phase, backup.Status.VolumeInfo, backup.Status.ValidationErrors, ...
  13. // Current thinking is to use a mock for c.backupper in the unit tests. But for the mocking we're doing,
  14. // we usually just control what the mocked method returns, which in this case is just an error. But
  15. // this run() function depends on c.backupper.Backup() mutating the backup, to determine if we should
  16. // proceed with the upload below. While you could argue (or not) that that's ok for the actual code,
  17. // it seems a bit "wrong" since the mocking code only deals with the return value (an error) and not the mutations
  18. // to the input objects. Does it make more sense have multiple return arguments, or is there some
  19. // other better way to do this?
  20. if err := c.backupper.Backup(backup, file); err != nil {
  21. errs = append(errs, err)
  22. }
  23.  
  24. if backup.Status.Phase == v1.BackupPhaseCompleted {
  25. // Current thinking is to use a mock for c.uploader in the unit tests.
  26. errs = append(errs, c.uploader.Upload(backup, file))
  27. }
  28.  
  29. if err := patchBackup(original, backup); err != nil {
  30. errs = append(errs, err)
  31. }
  32.  
  33. return kubeerrors.NewAggregate(errs)
  34. }
Add Comment
Please, Sign In to add comment