summaryrefslogtreecommitdiffhomepage
path: root/pkg/shim/utils/errors_test.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2021-06-29 10:53:10 -0700
committergVisor bot <gvisor-bot@google.com>2021-06-29 10:56:17 -0700
commit5f2b3728fc1d71d32912c57d948ba4b15c886f2a (patch)
tree1697b8bf8238bf3dc3b795b9eec01d9a777a882e /pkg/shim/utils/errors_test.go
parent5b2afd24a7ed6d626ede2d06d04378f95c3b62f8 (diff)
Redirect all calls from `errdefs.ToGRPC` to `utils.ErrToGRPC`
This is to ensure that Go 1.13 error wrapping is correctly translated to gRPC errors before returning from the shim. Updates #6225 PiperOrigin-RevId: 382120441
Diffstat (limited to 'pkg/shim/utils/errors_test.go')
-rw-r--r--pkg/shim/utils/errors_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/pkg/shim/utils/errors_test.go b/pkg/shim/utils/errors_test.go
new file mode 100644
index 000000000..0a8fe34c8
--- /dev/null
+++ b/pkg/shim/utils/errors_test.go
@@ -0,0 +1,50 @@
+// Copyright 2021 The gVisor 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
+//
+// https://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.
+
+package utils
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/containerd/containerd/errdefs"
+)
+
+func TestGRPCRoundTripsErrors(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ err error
+ test func(err error) bool
+ }{
+ {
+ name: "passthrough",
+ err: errdefs.ErrNotFound,
+ test: errdefs.IsNotFound,
+ },
+ {
+ name: "wrapped",
+ err: fmt.Errorf("oh no: %w", errdefs.ErrNotFound),
+ test: errdefs.IsNotFound,
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ if err := errdefs.FromGRPC(ErrToGRPC(tc.err)); !tc.test(err) {
+ t.Errorf("errToGRPC got %+v", err)
+ }
+ if err := errdefs.FromGRPC(ErrToGRPCf(tc.err, "testing %s", "123")); !tc.test(err) {
+ t.Errorf("errToGRPCf got %+v", err)
+ }
+ })
+ }
+}