| OLD | NEW |
| 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 Loading... |
| 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.ValueIn(singleErr) |
| 44 » » So(errors.ExtractData(singleErr, "element"), ShouldResemble, []s
tring{"ctx 123"}) | 43 » » So(ok, ShouldBeTrue) |
| 44 » » So(d.(string), ShouldEqual, "file.cfg") |
| 45 » » d, ok = element0Tag.ValueIn(singleErr) |
| 46 » » So(ok, ShouldBeTrue) |
| 47 » » So(d.(string), ShouldResemble, "ctx 123") |
| 45 }) | 48 }) |
| 46 | 49 |
| 47 Convey("Regular usage", t, func() { | 50 Convey("Regular usage", t, func() { |
| 48 v := Context{} | 51 v := Context{} |
| 49 | 52 |
| 50 v.Error("top %d", 1) | 53 v.Error("top %d", 1) |
| 51 v.Error("top %d", 2) | 54 v.Error("top %d", 2) |
| 52 | 55 |
| 53 v.SetFile("file_1.cfg") | 56 v.SetFile("file_1.cfg") |
| 54 v.Error("f1") | 57 v.Error("f1") |
| (...skipping 24 matching lines...) Expand all Loading... |
| 79 `in <unspecified file>: top 2`, | 82 `in <unspecified file>: top 2`, |
| 80 `in "file_1.cfg": f1`, | 83 `in "file_1.cfg": f1`, |
| 81 `in "file_1.cfg": f2`, | 84 `in "file_1.cfg": f2`, |
| 82 `in "file_1.cfg" (p 1): zzz 1`, | 85 `in "file_1.cfg" (p 1): zzz 1`, |
| 83 `in "file_1.cfg" (p 1 / p 2): zzz 2`, | 86 `in "file_1.cfg" (p 1 / p 2): zzz 2`, |
| 84 `in "file_1.cfg" (p 1): zzz 3`, | 87 `in "file_1.cfg" (p 1): zzz 3`, |
| 85 `in "file_2.cfg": zzz 4`, | 88 `in "file_2.cfg": zzz 4`, |
| 86 }) | 89 }) |
| 87 }) | 90 }) |
| 88 } | 91 } |
| OLD | NEW |