sync_result_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package container
  14. import (
  15. "errors"
  16. "testing"
  17. )
  18. func TestPodSyncResult(t *testing.T) {
  19. okResults := []*SyncResult{
  20. NewSyncResult(StartContainer, "container_0"),
  21. NewSyncResult(SetupNetwork, "pod"),
  22. }
  23. errResults := []*SyncResult{
  24. NewSyncResult(KillContainer, "container_1"),
  25. NewSyncResult(TeardownNetwork, "pod"),
  26. }
  27. errResults[0].Fail(errors.New("error_0"), "message_0")
  28. errResults[1].Fail(errors.New("error_1"), "message_1")
  29. // If the PodSyncResult doesn't contain error result, it should not be error
  30. result := PodSyncResult{}
  31. result.AddSyncResult(okResults...)
  32. if result.Error() != nil {
  33. t.Errorf("PodSyncResult should not be error: %v", result)
  34. }
  35. // If the PodSyncResult contains error result, it should be error
  36. result = PodSyncResult{}
  37. result.AddSyncResult(okResults...)
  38. result.AddSyncResult(errResults...)
  39. if result.Error() == nil {
  40. t.Errorf("PodSyncResult should be error: %q", result)
  41. }
  42. // If the PodSyncResult is failed, it should be error
  43. result = PodSyncResult{}
  44. result.AddSyncResult(okResults...)
  45. result.Fail(errors.New("error"))
  46. if result.Error() == nil {
  47. t.Errorf("PodSyncResult should be error: %q", result)
  48. }
  49. // If the PodSyncResult is added an error PodSyncResult, it should be error
  50. errResult := PodSyncResult{}
  51. errResult.AddSyncResult(errResults...)
  52. result = PodSyncResult{}
  53. result.AddSyncResult(okResults...)
  54. result.AddPodSyncResult(errResult)
  55. if result.Error() == nil {
  56. t.Errorf("PodSyncResult should be error: %q", result)
  57. }
  58. }