Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Side by Side Diff: upstream_errors_test.go

Issue 1249863004: Remove most error code from luci/gae (Closed) Base URL: https://github.com/luci/gae.git@simplify_rds
Patch Set: get rid of goofy lerrs imports Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « upstream_errors.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package gae
6
7 import (
8 "errors"
9 "sync"
10 "testing"
11
12 . "github.com/smartystreets/goconvey/convey"
13 )
14
15 type otherMEType []error
16
17 func (o otherMEType) Error() string { return "FAIL" }
18
19 func TestUpstreamErrors(t *testing.T) {
20 t.Parallel()
21
22 Convey("Test MultiError", t, func() {
23 Convey("nil", func() {
24 me := MultiError(nil)
25 So(me.Error(), ShouldEqual, "(0 errors)")
26 Convey("single", func() {
27 So(SingleError(error(me)), ShouldBeNil)
28 })
29 })
30 Convey("one", func() {
31 me := MultiError{errors.New("sup")}
32 So(me.Error(), ShouldEqual, "sup")
33 })
34 Convey("two", func() {
35 me := MultiError{errors.New("sup"), errors.New("what")}
36 So(me.Error(), ShouldEqual, "sup (and 1 other error)")
37 })
38 Convey("more", func() {
39 me := MultiError{errors.New("sup"), errors.New("what"), errors.New("nerds")}
40 So(me.Error(), ShouldEqual, "sup (and 2 other errors)")
41
42 Convey("single", func() {
43 So(SingleError(error(me)), ShouldResemble, error s.New("sup"))
44 })
45 })
46 Convey("convert", func() {
47 ome := otherMEType{errors.New("sup")}
48 So(FixError(ome), ShouldHaveSameTypeAs, MultiError{})
49 })
50 })
51
52 Convey("FixError passes through", t, func() {
53 e := errors.New("unique")
54 So(FixError(e), ShouldEqual, e)
55 })
56
57 Convey("SingleError passes through", t, func() {
58 e := errors.New("unique")
59 So(SingleError(e), ShouldEqual, e)
60 })
61 }
62
63 func TestLazyMultiError(t *testing.T) {
64 t.Parallel()
65
66 Convey("Test LazyMultiError", t, func() {
67 lme := LazyMultiError{Size: 10}
68 So(lme.Get(), ShouldEqual, nil)
69
70 e := errors.New("sup")
71 lme.Assign(6, e)
72 So(lme.Get(), ShouldResemble,
73 MultiError{nil, nil, nil, nil, nil, nil, e, nil, nil, ni l})
74
75 lme.Assign(2, e)
76 So(lme.Get(), ShouldResemble,
77 MultiError{nil, nil, e, nil, nil, nil, e, nil, nil, nil} )
78
79 So(func() { lme.Assign(20, e) }, ShouldPanic)
80
81 Convey("Try to freak out the race detector", func() {
82 lme := LazyMultiError{Size: 64}
83 Convey("all nils", func() {
84 wg := sync.WaitGroup{}
85 for i := 0; i < 64; i++ {
86 wg.Add(1)
87 go func(i int) {
88 lme.Assign(i, nil)
89 wg.Done()
90 }(i)
91 }
92 wg.Wait()
93 So(lme.Get(), ShouldBeNil)
94 })
95 Convey("every other", func() {
96 wow := errors.New("wow")
97 wg := sync.WaitGroup{}
98 for i := 0; i < 64; i++ {
99 wg.Add(1)
100 go func(i int) {
101 e := error(nil)
102 if i&1 == 1 {
103 e = wow
104 }
105 lme.Assign(i, e)
106 wg.Done()
107 }(i)
108 }
109 wg.Wait()
110 me := make(MultiError, 64)
111 for i := range me {
112 if i&1 == 1 {
113 me[i] = wow
114 }
115 }
116 So(lme.Get(), ShouldResemble, me)
117 })
118 Convey("all", func() {
119 wow := errors.New("wow")
120 wg := sync.WaitGroup{}
121 for i := 0; i < 64; i++ {
122 wg.Add(1)
123 go func(i int) {
124 lme.Assign(i, wow)
125 wg.Done()
126 }(i)
127 }
128 wg.Wait()
129 me := make(MultiError, 64)
130 for i := range me {
131 me[i] = wow
132 }
133 So(lme.Get(), ShouldResemble, me)
134 })
135 })
136 })
137 }
OLDNEW
« no previous file with comments | « upstream_errors.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698