Documentation ¶
Overview ¶
Package assertions is designed to be a collection of `.` importable, goconvey compatible testing assertions, in the style of "github.com/smarty/assertions".
Due to a bug/feature in goconvey1, files in this package end in `_tests.go`.
This is a signal to goconvey's internal stack traversal logic (used to print helpful assertion messages) that the assertions in this package should be considered 'testing code' and not 'tested code', and so should be skipped over when searching for the first stack frame containing the code under test.
Copyright 2015 The LUCI Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2018 The LUCI Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func ShouldBeLikeStatus(actual any, expected ...any) string
- func ShouldBeRPCAborted(actual any, expected ...any) string
- func ShouldBeRPCAlreadyExists(actual any, expected ...any) string
- func ShouldBeRPCDeadlineExceeded(actual any, expected ...any) string
- func ShouldBeRPCFailedPrecondition(actual any, expected ...any) string
- func ShouldBeRPCInternal(actual any, expected ...any) string
- func ShouldBeRPCInvalidArgument(actual any, expected ...any) string
- func ShouldBeRPCNotFound(actual any, expected ...any) string
- func ShouldBeRPCOK(actual any, expected ...any) string
- func ShouldBeRPCPermissionDenied(actual any, expected ...any) string
- func ShouldBeRPCUnauthenticated(actual any, expected ...any) string
- func ShouldBeRPCUnavailable(actual any, expected ...any) string
- func ShouldBeRPCUnknown(actual any, expected ...any) string
- func ShouldContainErr(actual any, expected ...any) string
- func ShouldErrLike(actual any, expected ...any) string
- func ShouldHaveAppStatus(actual any, expected ...any) string
- func ShouldHaveGRPCStatus(actual any, expected ...any) string
- func ShouldHaveRPCCode(actual any, expected ...any) string
- func ShouldPanicLike(function any, expected ...any) (ret string)
- func ShouldResembleProto(actual any, expected ...any) string
- func ShouldResembleProtoJSON(actual any, expected ...any) string
- func ShouldResembleProtoText(actual any, expected ...any) string
- func ShouldUnwrapTo(actual any, expected ...any) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShouldBeLikeStatus ¶
ShouldBeLikeStatus asserts that *status.Status `actual` has code `expected[0]`, that the actual message has a substring `expected[1]` and that the status details in expected[2:] as present in the actual status.
len(expected) must be at least 1.
Example:
// err must have a NotFound status So(s, ShouldBeLikeStatus, codes.NotFound) // and its message must contain "item not found" So(s, ShouldBeLikeStatus, codes.NotFound, "item not found") // and it must have a DebugInfo detail. So(s, ShouldBeLikeStatus, codes.NotFound, "item not found", &errdetails.DebugInfo{Details: "x"})
func ShouldBeRPCAborted ¶
ShouldBeRPCAborted asserts that "actual" is an error that has a gRPC code value of codes.Aborted.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCAlreadyExists ¶
ShouldBeRPCAlreadyExists asserts that "actual" is an error that has a gRPC code value of codes.AlreadyExists.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCDeadlineExceeded ¶
ShouldBeRPCDeadlineExceeded asserts that "actual" is an error that has a gRPC code value of codes.DeadlineExceeded.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCFailedPrecondition ¶
ShouldBeRPCFailedPrecondition asserts that "actual" is an error that has a gRPC code value of codes.FailedPrecondition.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCInternal ¶
ShouldBeRPCInternal asserts that "actual" is an error that has a gRPC code value of codes.Internal.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCInvalidArgument ¶
ShouldBeRPCInvalidArgument asserts that "actual" is an error that has a gRPC code value of codes.InvalidArgument.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCNotFound ¶
ShouldBeRPCNotFound asserts that "actual" is an error that has a gRPC code value of codes.NotFound.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCOK ¶
ShouldBeRPCOK asserts that "actual" is an error that has a gRPC code value of codes.OK.
Note that "nil" has an codes.OK value.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCPermissionDenied ¶
ShouldBeRPCPermissionDenied asserts that "actual" is an error that has a gRPC code value of codes.PermissionDenied.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCUnauthenticated ¶
ShouldBeRPCUnauthenticated asserts that "actual" is an error that has a gRPC code value of codes.Unauthenticated.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCUnavailable ¶
ShouldBeRPCUnavailable asserts that "actual" is an error that has a gRPC code value of codes.Unavailable.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldBeRPCUnknown ¶
ShouldBeRPCUnknown asserts that "actual" is an error that has a gRPC code value of codes.Unknown.
One additional "expected" string may be optionally included. If included, the gRPC error's message is asserted to contain the expected string.
func ShouldContainErr ¶
ShouldContainErr checks if an `errors.MultiError` on the left side contains as one of its errors an `error` or `string` on the right side. If nothing is provided on the right, checks that the left side contains at least one non-nil error. If nil is provided on the right, checks that the left side contains at least one nil, even if it contains other errors.
Equivalent to calling ShouldErrLike on each `error` in an `errors.MultiError` and succeeding as long as one of the ShouldErrLike calls succeeds.
To avoid confusion, explicitly rejects the special case where the right side is an `errors.MultiError`.
func ShouldErrLike ¶
ShouldErrLike compares an `error` or `string` on the left side, to `error`s or `string`s on the right side.
If multiple errors/strings are provided on the righthand side, they must all be contained in the stringified error on the lefthand side.
If the righthand side is the singluar `nil`, this expects the error to be nil.
Example:
// Usage Equivalent To So(err, ShouldErrLike, "custom") // `err.Error()` ShouldContainSubstring "custom" So(err, ShouldErrLike, io.EOF) // `err.Error()` ShouldContainSubstring io.EOF.Error() So(err, ShouldErrLike, "EOF") // `err.Error()` ShouldContainSubstring "EOF" So(err, ShouldErrLike, "thing", "other", "etc.") // `err.Error()` contains all of these substrings. So(nilErr, ShouldErrLike, nil) // nilErr ShouldBeNil So(nonNilErr, ShouldErrLike, "") // nonNilErr ShouldNotBeNil
func ShouldHaveAppStatus ¶
ShouldHaveAppStatus asserts that error `actual` has an application-specific status and it matches the expectations. See ShouldBeLikeStatus for the format of `expected`. See appstatus package for application-specific statuses.
func ShouldHaveGRPCStatus ¶
ShouldHaveGRPCStatus asserts that error `actual` has a GRPC status and it matches the expectations. See ShouldBeStatusLike for the format of `expected`. The status is extracted using status.FromError.
func ShouldHaveRPCCode ¶
ShouldHaveRPCCode is a goconvey assertion, asserting that the supplied "actual" value has a gRPC code value and, optionally, errors like a supplied message string.
If no "expected" arguments are supplied, ShouldHaveRPCCode will assert that the result is codes.OK.
The first "expected" argument, if supplied, is the gRPC codes.Code to assert.
A second "expected" string may be optionally included. If included, the gRPC error message is asserted to contain the expected string using convey.ShouldContainSubstring.
func ShouldPanicLike ¶
ShouldPanicLike is the same as ShouldErrLike, but with the exception that it takes a panic'ing func() as its first argument, instead of the error itself.
func ShouldResembleProto ¶
ShouldResembleProto determines if two values are deeply equal, using the following rules:
- proto equality is defined by proto.Equal,
- if a type has an .Equal method, equality is defined by that method,
- in the absence of the above, deep equality is defined by recursing over structs, maps and slices in the usual way.
See github.com/google/go-cmp/cmp#Equal for more details.
This method is similar to goconvey's ShouldResemble, except that supports proto messages at the top-level or nested inside other types.
func ShouldResembleProtoJSON ¶
ShouldResembleProtoJSON is like ShouldResembleProto, but expected is protobuf text. actual must be a message. A slice of messages is not supported.
func ShouldResembleProtoText ¶
ShouldResembleProtoText is like ShouldResembleProto, but expected is protobuf text. actual must be a message. A slice of messages is not supported.
func ShouldUnwrapTo ¶
ShouldUnwrapTo asserts that an error, when unwrapped, equals another error.
The actual field will be unwrapped using errors.Unwrap and then compared to the error in expected.
Types ¶
This section is empty.