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

Side by Side Diff: common/config/validation/validation_test.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor Created 3 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
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package validation 5 package validation
6 6
7 import ( 7 import (
8 "testing" 8 "testing"
9 9
10 "github.com/luci/luci-go/common/errors"
11 "github.com/luci/luci-go/common/logging" 10 "github.com/luci/luci-go/common/logging"
12 11
13 . "github.com/smartystreets/goconvey/convey" 12 . "github.com/smartystreets/goconvey/convey"
14 ) 13 )
15 14
16 func TestValidation(t *testing.T) { 15 func TestValidation(t *testing.T) {
17 t.Parallel() 16 t.Parallel()
18 17
19 Convey("No errors", t, func() { 18 Convey("No errors", t, func() {
20 v := Context{} 19 v := Context{}
(...skipping 12 matching lines...) Expand all
33 32
34 v.SetFile("file.cfg") 33 v.SetFile("file.cfg")
35 v.Enter("ctx %d", 123) 34 v.Enter("ctx %d", 123)
36 v.Error("blah %s", "zzz") 35 v.Error("blah %s", "zzz")
37 err := v.Finalize() 36 err := v.Finalize()
38 So(err, ShouldHaveSameTypeAs, &Error{}) 37 So(err, ShouldHaveSameTypeAs, &Error{})
39 So(err.Error(), ShouldEqual, `in "file.cfg" (ctx 123): blah zzz` ) 38 So(err.Error(), ShouldEqual, `in "file.cfg" (ctx 123): blah zzz` )
40 39
41 singleErr := err.(*Error).Errors[0] 40 singleErr := err.(*Error).Errors[0]
42 So(singleErr.Error(), ShouldEqual, `in "file.cfg" (ctx 123): bla h zzz`) 41 So(singleErr.Error(), ShouldEqual, `in "file.cfg" (ctx 123): bla h zzz`)
43 » » So(errors.ExtractData(singleErr, "file"), ShouldEqual, "file.cfg ") 42 » » d, ok := fileTag.In(singleErr)
44 » » So(errors.ExtractData(singleErr, "element"), ShouldResemble, []s tring{"ctx 123"}) 43 » » So(ok, ShouldBeTrue)
44 » » So(d, ShouldEqual, "file.cfg")
45
46 » » elts, ok := elementTag.In(singleErr)
47 » » So(ok, ShouldBeTrue)
48 » » So(elts, ShouldResemble, []string{"ctx 123"})
45 }) 49 })
46 50
47 Convey("Regular usage", t, func() { 51 Convey("Regular usage", t, func() {
48 v := Context{} 52 v := Context{}
49 53
50 v.Error("top %d", 1) 54 v.Error("top %d", 1)
51 v.Error("top %d", 2) 55 v.Error("top %d", 2)
52 56
53 v.SetFile("file_1.cfg") 57 v.SetFile("file_1.cfg")
54 v.Error("f1") 58 v.Error("f1")
(...skipping 24 matching lines...) Expand all
79 `in <unspecified file>: top 2`, 83 `in <unspecified file>: top 2`,
80 `in "file_1.cfg": f1`, 84 `in "file_1.cfg": f1`,
81 `in "file_1.cfg": f2`, 85 `in "file_1.cfg": f2`,
82 `in "file_1.cfg" (p 1): zzz 1`, 86 `in "file_1.cfg" (p 1): zzz 1`,
83 `in "file_1.cfg" (p 1 / p 2): zzz 2`, 87 `in "file_1.cfg" (p 1 / p 2): zzz 2`,
84 `in "file_1.cfg" (p 1): zzz 3`, 88 `in "file_1.cfg" (p 1): zzz 3`,
85 `in "file_2.cfg": zzz 4`, 89 `in "file_2.cfg": zzz 4`,
86 }) 90 })
87 }) 91 })
88 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698