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

Side by Side Diff: common/testing/assertions/error_tests.go

Issue 2576923003: Implement config service cache on top of datastore (Closed)
Patch Set: Relocated, fix, split integration test, rebase. Created 3 years, 11 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 | « appengine/gaemiddleware/routes.go ('k') | luci_config/appengine/backend/datastore/ds.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 assertions 5 package assertions
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 9
10 "github.com/luci/luci-go/common/errors"
11
10 "github.com/smartystreets/assertions" 12 "github.com/smartystreets/assertions"
11 ) 13 )
12 14
13 // ShouldErrLike compares an `error` or `string` on the left side, to an `error` 15 // ShouldErrLike compares an `error` or `string` on the left side, to an `error`
14 // or `string` on the right side. 16 // or `string` on the right side.
15 // 17 //
16 // If the righthand side is omitted, this expects `actual` to be nil. 18 // If the righthand side is omitted, this expects `actual` to be nil.
17 // 19 //
18 // If a singular righthand side is provided, this expects the stringified 20 // If a singular righthand side is provided, this expects the stringified
19 // `actual` to contain the stringified `expected[0]` to be a substring of it. 21 // `actual` to contain the stringified `expected[0]` to be a substring of it.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 f, ok := function.(func()) 62 f, ok := function.(func())
61 if !ok { 63 if !ok {
62 return fmt.Sprintf("unknown argument type %T, expected `func()`" , function) 64 return fmt.Sprintf("unknown argument type %T, expected `func()`" , function)
63 } 65 }
64 defer func() { 66 defer func() {
65 ret = ShouldErrLike(recover(), expected...) 67 ret = ShouldErrLike(recover(), expected...)
66 }() 68 }()
67 f() 69 f()
68 return ShouldErrLike(nil, expected...) 70 return ShouldErrLike(nil, expected...)
69 } 71 }
72
73 // ShouldUnwrapTo asserts that an error, when unwrapped, equals another error.
74 //
75 // The actual field will be unwrapped using errors.Unwrap and then compared to
76 // the error in expected.
77 func ShouldUnwrapTo(actual interface{}, expected ...interface{}) string {
78 act, ok := actual.(error)
79 if !ok {
80 return fmt.Sprintf("ShouldUnwrapTo requires an error actual type , got %T", act)
81 }
82
83 if len(expected) != 1 {
84 return fmt.Sprintf("ShouldUnwrapTo requires exactly one expected value, got %d", len(expected))
85 }
86 exp, ok := expected[0].(error)
87 if !ok {
88 return fmt.Sprintf("ShouldUnwrapTo requires an error expected ty pe, got %T", expected[0])
89 }
90
91 return assertions.ShouldEqual(errors.Unwrap(act), exp)
92 }
OLDNEW
« no previous file with comments | « appengine/gaemiddleware/routes.go ('k') | luci_config/appengine/backend/datastore/ds.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698