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

Unified Diff: appengine/ephelper/assertions/errors.go

Issue 1750143003: Remove ephelper and other endpoints code. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/apigen_examples/dumb_counter_mvm/service/main.go ('k') | appengine/ephelper/context.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/ephelper/assertions/errors.go
diff --git a/appengine/ephelper/assertions/errors.go b/appengine/ephelper/assertions/errors.go
deleted file mode 100644
index f52c1c59d8cd4edb5e0ae35d9bff40e2c5ebf868..0000000000000000000000000000000000000000
--- a/appengine/ephelper/assertions/errors.go
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package assertions
-
-import (
- "fmt"
-
- "github.com/GoogleCloudPlatform/go-endpoints/endpoints"
-
- "github.com/luci/luci-go/common/testing/assertions"
- "github.com/smartystreets/goconvey/convey"
-)
-
-// ShouldHaveAPIError is a goconvey assertion, asserting that the supplied
-// "actual" value is an *endpoints.APIError.
-//
-// One additional "expected" string may be optionally included. If included, the
-// *endpoints.APIError's message is asserted to contain the expected string
-// using ShouldErrorLike.
-func ShouldHaveAPIError(actual interface{}, expected ...interface{}) string {
- if len(expected) != 1 {
- return "exactly one expected argument must be supplied, and it must be an *endpoints.APIError."
- }
- eerr, ok := expected[0].(*endpoints.APIError)
- if !ok {
- return "expected argument must be an *endpoints.APIError."
- }
-
- if err := convey.ShouldHaveSameTypeAs(actual, (*endpoints.APIError)(nil)); err != "" {
- return err
- }
-
- aerr := actual.(*endpoints.APIError)
-
- // Create copies and strip the messages so we can compare values. We do this
- // rather than assert individual properties because the joint output is nicer
- // to look at.
- aerrCopy := *aerr
- aerrCopy.Msg = ""
-
- eerrCopy := *eerr
- eerrCopy.Msg = ""
-
- if err := convey.ShouldResemble(aerrCopy, eerrCopy); err != "" {
- return err
- }
-
- // If a ShouldErrLike string was supplied, compare that, too.
- if eerr.Msg != "" {
- return assertions.ShouldErrLike(aerr, eerr.Msg)
- }
- return ""
-}
-
-// ShouldBeInternalServerError asserts that "actual" is an *endpoints.APIError
-// generated by endpoints.NewInternalServerError.
-//
-// One additional "expected" string may be optionally included. If included, the
-// *endpoints.APIError's message is asserted to contain the expected string
-// using ShouldErrorLike.
-func ShouldBeInternalServerError(actual interface{}, expected ...interface{}) string {
- msg, err := getErrLikeMsg(expected)
- if err != "" {
- return err
- }
- return ShouldHaveAPIError(actual, endpoints.NewInternalServerError(msg))
-}
-
-// ShouldBeBadRequestError asserts that "actual" is an *endpoints.APIError
-// generated by endpoints.NewBadRequestError.
-//
-// One additional "expected" string may be optionally included. If included, the
-// *endpoints.APIError's message is asserted to contain the expected string
-// using ShouldErrorLike.
-func ShouldBeBadRequestError(actual interface{}, expected ...interface{}) string {
- msg, err := getErrLikeMsg(expected)
- if err != "" {
- return err
- }
- return ShouldHaveAPIError(actual, endpoints.NewBadRequestError(msg))
-}
-
-// ShouldBeUnauthorizedError asserts that "actual" is an *endpoints.APIError
-// generated by endpoints.NewUnauthorizedError.
-//
-// One additional "expected" string may be optionally included. If included, the
-// *endpoints.APIError's message is asserted to contain the expected string
-// using ShouldErrorLike.
-func ShouldBeUnauthorizedError(actual interface{}, expected ...interface{}) string {
- msg, err := getErrLikeMsg(expected)
- if err != "" {
- return err
- }
- return ShouldHaveAPIError(actual, endpoints.NewUnauthorizedError(msg))
-}
-
-// ShouldBeNotFoundError asserts that "actual" is an *endpoints.APIError
-// generated by endpoints.NewNotFoundError.
-//
-// One additional "expected" string may be optionally included. If included, the
-// *endpoints.APIError's message is asserted to contain the expected string
-// using ShouldErrorLike.
-func ShouldBeNotFoundError(actual interface{}, expected ...interface{}) string {
- msg, err := getErrLikeMsg(expected)
- if err != "" {
- return err
- }
- return ShouldHaveAPIError(actual, endpoints.NewNotFoundError(msg))
-}
-
-// ShouldBeForbiddenError asserts that "actual" is an *endpoints.APIError
-// generated by endpoints.NewForbiddenError.
-//
-// One additional "expected" string may be optionally included. If included, the
-// *endpoints.APIError's message is asserted to contain the expected string
-// using ShouldErrorLike.
-func ShouldBeForbiddenError(actual interface{}, expected ...interface{}) string {
- msg, err := getErrLikeMsg(expected)
- if err != "" {
- return err
- }
- return ShouldHaveAPIError(actual, endpoints.NewForbiddenError(msg))
-}
-
-// ShouldBeConflictError asserts that "actual" is an *endpoints.APIError
-// generated by endpoints.NewConflictError.
-//
-// One additional "expected" string may be optionally included. If included, the
-// *endpoints.APIError's message is asserted to contain the expected string
-// using ShouldErrorLike.
-func ShouldBeConflictError(actual interface{}, expected ...interface{}) string {
- msg, err := getErrLikeMsg(expected)
- if err != "" {
- return err
- }
- return ShouldHaveAPIError(actual, endpoints.NewConflictError(msg))
-}
-
-func getErrLikeMsg(expected []interface{}) (string, string) {
- switch len(expected) {
- case 0:
- return "", ""
- case 1:
- s, ok := expected[0].(string)
- if !ok {
- return "", fmt.Sprintf("expected message must be string, not %T", expected[0])
- }
- return s, ""
-
- default:
- return "", "expected must have at most one argument"
- }
-}
« no previous file with comments | « appengine/apigen_examples/dumb_counter_mvm/service/main.go ('k') | appengine/ephelper/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698