multierror_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2015 Google Inc. All rights reserved.
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package martian
  15. import (
  16. "fmt"
  17. "reflect"
  18. "testing"
  19. )
  20. func TestMultiError(t *testing.T) {
  21. merr := NewMultiError()
  22. if !merr.Empty() {
  23. t.Fatal("Empty(): got false, want true")
  24. }
  25. var errs []error
  26. for i := 0; i < 3; i++ {
  27. err := fmt.Errorf("%d. error", i)
  28. errs = append(errs, err)
  29. merr.Add(err)
  30. }
  31. if merr.Empty() {
  32. t.Fatal("Empty(): got true, want false")
  33. }
  34. if got, want := merr.Errors(), errs; !reflect.DeepEqual(got, want) {
  35. t.Errorf("Errors(): got %v, want %v", got, want)
  36. }
  37. want := "0. error\n1. error\n2. error"
  38. if got := merr.Error(); got != want {
  39. t.Errorf("Error(): got %q, want %q", got, want)
  40. }
  41. }